An array in C # implicitly refers to a reference type:
object[] listString = new string[] { "string1", "string2" };
But not by type of value, so if you change string to int , you will get a compiled error:
object[] listInt = new int[] {0, 1};
Now the problem is that you declare an int array as two syntaxes, below which the int type is not explicitly declared, just differentiate only with new[] , the compiler will handle it differently:
object[] list1 = { 0, 1 };
You will get object[] list1 = { 0, 1 }; compiled successfully, but object[] list2= new[] {0, 1}; compiled error.
C # compiler seems to be considering
object[] list1 = { 0, 1 };
but
object[] list1 = new object[]{ 0, 1 };
but
object[] list2 = new[] { 0, 1 };
but
object[] list2 = new int[]{ 0, 1 };
Why does the C # compiler behave differently in this case?
arrays c #
Cuong Le May 09 '13 at 8:00 2013-05-09 08:00
source share