Search code examples
c#.netgenericsc#-3.0

What does "out" mean before a Generic type parameter?


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

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

MSDN Source

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

What does out mean in a generic type?


Solution

  • 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.

    See out (Generic Modifier) and in (Generic Modifier) on MSDN.