什么"明"泛型类型参数前是什么意思?参数、类型、QUOT

2023-09-03 09:59:50 作者:回眸抹去乄一场空

我刚刚看到一个不熟悉的语法,同时寻找 GROUPBY 返回类型:

I've just saw an unfamiliar syntax while looking for GroupBy return type:

public interface IGrouping<out TKey, out TElement> : IEnumerable<TElement>

MSDN来源

我知道什么呢退出平均的方法,而不是在一个泛型接口。

I know what does out mean in methods, but not in a generics interface.

这是什么退出是什么意思?

推荐答案

这是两个通用改性剂之一介绍了C#4.0(Visual Studio 2010中)。

It is one of the two generic modifiers introduces in C# 4.0 (Visual Studio 2010).

这意味着它在声明的泛型参数是协变的。

It signifies that the generic parameter it is declared on is covariant.

修改意味着它是在为逆变声明的泛型参数。

The in modifier signifies the generic parameter it is declared on is contravariant.

请参阅出来(一般修改)和的在MSDN上(一般修改)。