1

Why is IEnumerable's generic parameter covariant, and IList's is not? So that, given this:

class base1 {}
class derived : base1 {}

var list1 = new List<derived>();

I can do this:

IEnumerable<base1> list3 = list1;

But can't do this:

IList<base1> list2 = list1;

I just wonder why the restriction on IList which is derived from IEnumerable, which is covariant

user5080246
  • 193
  • 1
  • 11

0 Answers0