C# newbie List<Interface> question

Posted by newB on Stack Overflow See other posts from Stack Overflow or by newB
Published on 2009-08-04T15:29:16Z Indexed on 2010/05/30 1:12 UTC
Read the original article Hit count: 252

Filed under:
|

If you have an Interface IFoo and a class Bar : IFoo, why can you do the following:

List<IFoo> foo = new List<IFoo>();  
foo.Add(new Bar());

But you cannot do:

List<IFoo> foo = new List<Bar>();

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics