Assume I have interface and class:
Код: Выделить всё
public interface ITree {} public class Tree : ITree {}
Код: Выделить всё
IEnumerable
Код: Выделить всё
IEnumerable trees = new List();
Код: Выделить всё
public void Do() where T : ITree { IEnumerable trees = new List(); }
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?) D:\lab\Lab.General\Lab.General\Program.cs 83 40 Lab.General
Why covariance does not work in this case?
Источник: https://stackoverflow.com/questions/127 ... ric-method