为什么下面的代码会出现错误?
无效方差:类型参数“T”必须始终有效
'UserQuery.IItem.GetList()'。 “T”是协变的。
public interface IFoo {}
public interface IBar<T> where T : IFoo {}
public interface IItem<out T> where T: IFoo
{
IEnumerable<IBar<T>> GetList();
}
接口IBar
and IItem
不同意差异:在你的IBar
声明中,T 不是协变的,因为没有out
关键字,而在IITem
T 是协变的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)