0

问题:

interface ICovariant<out R>
{
    // The following statement generates a compiler error
    // because you can use only contravariant or invariant types
    // in generic constraints.
    // void DoSomething<T>() where T : R;
}

为什么在这种情况下不允许对方法的通用约束。

编辑:大声笑我找到了答案,方法中的通用类型“T”实际上是一个参数(或输入),因此它不是协变的。

4

0 回答 0