In C# standard is written that exsists an implicit conversion between array according to the following rules:
From an array-type S with an element type SE to an array-type T with an element type TE, provided all of the following are true:
- S and T differ only in element type. In other words, S and T have the same number of dimensions.
but if I make:
int[] j = { 1, 2 };
int[] k = { 1 };
k = j;
no compiler error is emitted. Maybe I didn't understand the meaning of this rule...
- Both SE and TE are reference-types.
but, again, in the example above the element type of j and k are value types.
- An implicit reference conversion exists from SE to TE.
here if I have:
int[] j = { 1, 2 };
short[] k = { 1, 5 };
j = k;
it seems like there can be an implicit conversion from element of type short to element of type int but the complier not compile. Emit an error.
Sincerely I can't figure how this rule work!
iandjare the same type,int[]. The dimensionality and element type are both identical.string[]toobject[]is not an identity conversion.int, norshortare reference-types. And there is no implicit reference conversion between them.shorttointconversion covered by 6.1.2 Implicit numeric conversions.