Why does C#/CLR not support method override co/contra-variance?

前端 未结 5 486
死守一世寂寞
死守一世寂寞 2020-12-02 01:48

There are quite a few questions & answers about hacking around the limitation of C# not allowing method return (and argument) types to be changed to compatible types on

5条回答
  •  渐次进展
    2020-12-02 02:16

    Seams introducing covariance of return value has no essential drawback as Java and C++ have used. However, there's real confusion cased by introducing contra-variance of formal parameter. I think this answer https://stackoverflow.com/a/3010614/1443505 in C++ is also valid for C#.

提交回复
热议问题