为什么可以编译方法时属性会出错?
public interface IFoo {}
public interface IBar<out T> where T : IFoo {}
public interface IItem<out T> where T: IFoo
{
// IEnumerable<IBar<T>> GetList(); // works
IEnumerable<IBar<T>> ItemList { get; set; } // Error!
}
错误:
无效方差:类型参数“T”必须在“UserQuery.IItem<T>.ItemList”上逆变有效。“T”是协变的。