This is a matter of dispersion, not polymorphism.
If List-of-Foo was also IList-of-IBar, the following will work:
class Another : IBar {} IList<IBar> list = new List<Foo>(); list.Add(new Another());
Then we added Another to the Foo list. This is mistake. The compiler stopped your error.
Note that recent versions of /.net compilers support dispersion through "in" / "out". Thus, List-of-Foo is great for IEnumerable-of-IBar. Because it is guaranteed to return Foo (not accept them), and all Foo are also IBar - therefore, it is safe.
source share