C# generics covariance
I've posted about this before, largely covariance is possible in C# delegates but not featured in generics. However the CLI supports generics through out as this post from Rick Byers indicates.
...CLI supports covariant and contravariant generic parameters, with the following characteristics:
· It is type-safe (based on purely static checking)
· Simplicity: in particular, variance is only permitted on generic interfaces and generic delegates (not classes or value-types)
· Languages not wishing to support variance can ignore the feature, and treat all generic types as non-variant.
· Enable implementation of more complex covariance scheme as used in some languages, e.g. Eiffel.
The discussion in that post on Eiffel supporting covariance by default and the appoach taken by Java 1.5 in its generics support is well worth a read. Rick also shows how you can use type inheritance and base type constraint to allow for covariant style behaviour in C#.