TaylorMichaelL
It isn't really bizarre. You are making one false assumption. You are assuming that all elements in the array are the same and hence the CLR should be able to figure it out but that is not a valid assumption unless the CLR first traverses all elements in the array to ensure that it is true. It also might only be true at the very moment in time when the CLR checked it but not true thereafter. Case in point:
object[] values = new object[] { "First", "Second", "Third" };
string[] stringValues = (string[])values;
At this point the CLR could traverse the list and verify that the elements are all strings. But at any point after this it might not be true:
values[1] = 10;
Now if I start enumerating stringValues bad things will happen as one of the elements is no longer a string. Instead the CLR follows the more limited, faster, safer approach of only allowing the conversion if the actual base type (the array type) matches the cast. If it does then it is allowed, if it doesn't then it should error out.
Michael Taylor - 10/29/07
http://p3net.mvps.org