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

前端 未结 4 2075
我寻月下人不归
我寻月下人不归 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:56

    out keyword in this context would indicate the corresponding type parameter to be covariant simply speaking - covariance enables you to use a more derived type than that specified by the generic parameter.

    BTW, see this ten part series from Eric Lippert to understand more about covariance and contra-variance: http://blogs.msdn.com/b/ericlippert/archive/2007/10/16/covariance-and-contravariance-in-c-part-one.aspx

提交回复
热议问题