且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么列表< T>不上协接口MyInterface的<有效;出T>

更新时间:2022-04-26 07:52:40

@克雷格的回答是正确的。要解决,将其更改为:

@Craig's answer is correct. To resolve, change it to:

IEnumerable<T> MakeStuff()



编辑:至于为什么,看的的IEnumerable&LT; T&GT;接口​​>:

public interface IEnumerable<out T> : IEnumerable



注意的&IList的LT; T&GT;接口​​>没有out关键字。方差支持在接口和委托,而不是类泛型类型参数,所以它并不适用于列出&LT; T&GT;

Note that the IList<T> Interface does not have the out keyword. Variance is supported for generic type parameters in interfaces and delegates, not classes, so it doesn't apply to List<T>.