What does “out” mean before a Generic type parameter?

前端 未结 4 1983
我寻月下人不归
我寻月下人不归 2021-02-05 07:18

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

public interface IGrouping : IEnumerable<         


        
4条回答
  •  感情败类
    2021-02-05 07:46

    out just means that the type is only used for output e.g.

    public interface Foo
    {
       T Bar()
    }
    

    There also is a modifier in that means that the type is only used for input e.g.

    public interface Foo
    {
        int Bar(T x)
    }
    

    These are used because Interfaces with in are covariant in T and Interfaces with out are contravariant in T.

提交回复
热议问题