ref and out parameters in C# and cannot be marked as variant

后端 未结 4 1983
-上瘾入骨i
-上瘾入骨i 2020-11-29 05:09

What does the statement mean?

From here

ref and out parameters in C# and cannot be marked as variant.

1) Does it mean

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 05:35

    But, the following code can be compiled:

    interface IFoo
    {
        T Get();
    
        //bool TryGet(out T value); // doesn't work: Invalid variance: The type parameter 'T' must be invariantly valid on 'IFoo.TryGet(out T)'. 'T' is covariant.
    
        bool TryGet(Action value); // works!
    }
    

提交回复
热议问题