Does C# 4's covariance support nesting of generics?

Posted by Scott Bilas on Stack Overflow See other posts from Stack Overflow or by Scott Bilas
Published on 2010-04-21T16:09:00Z Indexed on 2010/04/21 21:23 UTC
Read the original article Hit count: 121

Filed under:
|

I don't understand why 'x' below converts, but 'y' and 'z' do not.

var list = new List<List<int>>();

IEnumerable<List<int>> x = list;
List<IEnumerable<int>> y = list;
IEnumerable<IEnumerable<int>> z = list;

Does the new covariance feature simply not work on generics of generics or am I doing something wrong? (I'd like to avoid using .Cast<> to make y and z work.)

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#4.0