I do not understand why the "x" below converts, but the "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;
Is the new covariance function simply unworkable for generic generics, or am I doing something wrong? (I would like to avoid using .Cast <> to make y and z work.)
"z" excellent in C # 4.0 IEnumerable<T>is covariant. List<T>however, you cannot make "y" work.
IEnumerable<T>
List<T>
Intuitively, if it were then it would be true:
List<IEnumerable<int>> y = list y.Add(new Stack<int>());
, "" List<int>.
List<int>
. -, , , "int", .
-, :
var list = new List<List<String>>(); IEnumerable<IEnumerable<object>> z = list;
List of List IEnumerable IEnumerables , . .