Why can you not cast a object which at runtime has type object {System.Collections.Generic.List<string[]>}
as an ICollection<object>
?
I'm sure its something obvious but I cant figure it out.
It gives the exception –
Unable to cast object of type
'System.Collections.Generic.List1[System.String[]]' to type
1[System.Object]'.
'System.Collections.Generic.ICollection
Best Answer
Before C# 4.0, generics are not covariant. If you are not using C# 4.0, you can accomplish this cast like this: