C# : What is wrong with this?

public int[] DaysOfMonths(int MyYear)

{

return {31, (System.DateTime.DaysInMonth(MyYear,2)), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

}

}



Answer this question

C# : What is wrong with this?

  • Rajat Solanki

    Mattias,

    Thank you; it works.

    However,

    Why does

    return @"Mystring";

    work without requiring

    return new string @"My String";


  • Matti Niskasaari

    Becuase it's a string literal - the compiler knows that things inside double quotes are strings. It can't know that what you happen to write inside those curly braces should be interpreted as an int[] unless you specify the type.

     



  • Nick Burnett

    You have to write

    return new int[] {31, ....



  • Tim Wright

    Thanks, once more.

    I should remember that C# does not have the VB Variant data type.


  • C# : What is wrong with this?