c# Generics problem

Posted by UpTheCreek on Stack Overflow See other posts from Stack Overflow or by UpTheCreek
Published on 2010-06-14T10:30:47Z Indexed on 2010/06/14 10:32 UTC
Read the original article Hit count: 295

Filed under:
|

Can anyone tell me why this does not work? I would have thought the constraint would make it valid.

public class ClassA<T> where T : ICommon
{
    public ClassA()
    {
        ClassB b = new b();
        IEnumerable<T> alist = new IList<T>;
        b.items = alist; 
        //Error: cannot convert from IEnumerable<T> to IEnumerable<ICommon>'
    }

}


public class ClassB
{
    IEnumerable<ICommon> items { get; set;}
    ....
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics