【发布时间】:2012-09-18 20:36:14
【问题描述】:
为什么方法可以编译时属性报错?
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
.ItemList”上。 'T' 是协变的。
【问题讨论】:
标签: c# covariance