Fabrizio <nospam@nospam.com> wrote:[color=blue]
> I cannot figure why it isn't possible to cast a struct array to an object
> array.[/color]
Think about how they're both in memory. In an object[], there's a list
of references, one after another, at 4-byte intervals (on x86, anyway).
Your struct takes up 8 bytes - so the array of structs occurs with one
at every 8 bytes.
Now put boxing in as well - your "cast" would actually have to create a
new array, box every element in the original and put a reference to
each boxed value into the new array. Nasty!
The reason it works when you cast (say) MyClass[] to object[] is that
none of that needs to happen - an array of MyClass references *is* an
array of object references already. (The only problem is if you then
try to say foo[0] = new object() - you'll get a runtime exception.)
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too