C# 4.0 RC, Silverlight 4.0 RC Covariance

Posted by Ant on Stack Overflow See other posts from Stack Overflow or by Ant
Published on 2010-04-01T06:26:13Z Indexed on 2010/04/01 6:53 UTC
Read the original article Hit count: 527

Filed under:


I am trying to develop a Silverlight 4 application using C# 4.0. I have a case like this:

public class Foo<T> : IEnumerable<T>


public class MyBaseType : MyInterface

And the usage where I am having problems:

Foo<MyBaseType> aBunchOfStuff = new Foo<MyBaseType>();
Foo<MyInterface> moreGeneralStuff = myListOFStuff;

Now I believe this was impossible in C# 3.0 because generic type were "Invariant". However I thought this was possible in C# 4.0 through the new covariance for generics technology?

As I understand it, in C# 4.0 a lot of common interfaces (like IEnumerable) have been modified to support variance. In this case does my Foo class need to anything special in order to become covariant?

And is covariance supported in Silverlight 4 (RC) ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about c#4.0