Covariance and Contravariance on the same type argument

后端 未结 7 748
时光取名叫无心
时光取名叫无心 2021-01-02 06:45

The C# spec states that an argument type cannot be both covariant and contravariant at the same time.

This is apparent when creating a covariant or contravariant int

7条回答
  •  感动是毒
    2021-01-02 06:50

    Covariance and contravariance are mutually exclusive. Your question is like asking if set A can be both a superset of set B and a subset of set B. In order for set A to be both a subset and superset of set B, set A must be equal to set B, so then you would just ask if set A is equal to set B.

    In other words, asking for covariance and contravariance on the same argument is like asking for no variance at all (invariance), which is the default. Thus, there's no need for a keyword to specify it.

提交回复
热议问题