Why does
var value = new Guid[]{};
var b = (object[])value;
results in
Cannot cast 'value' (which has an actual type of 'System.Guid[]') to 'object[]'
?
UPDATE
Sorry for inaccuracy. The real code is:
private void SetEditors(object value)
{
var array = value as object[];
...
}
and array is null if value is Guid array.
To answer the "why" part- only arrays of reference types are covariant.
So you can write:
But you can’t write:
Personally I think it’s a shame that even the first version is allowed, but that’s a different story.
This is all detailed in section 6.1.6 of the C# 4 spec (Implicit Reference Conversions):