Covariance Also in 3.5 / 2.0?

女生的网名这么多〃 提交于 2019-12-10 18:05:20

问题


weird problem...

Ive implemented covariance from example .

My target FW is 4.0.

How ever . I wanted to see if it fails on 3.5 /2 -> but it wont.

It cant be since covariance is from FW4.0.

After changing to 3.0 i Build and see : (+wont fail on runtime)


回答1:


Covariance was supported in framework 3, but not implemented in the compiler. You are using compiler 4 targeting framework 3.

This is mentioned in an Eric Lippert blog post, I'll see if I can find it..

EDIT

To further clarify,: The Common Language Runtime and the C# compiler (csc.exe) are two separate things. Covariance and Contravariance where introduced to the CLR at version 2.0. They were not introduced to C# until version 4. You are using Compiler 4 to build version 3 IL which is why it works.




回答2:


The CLR has supported covariant and contravariant generic type parameters since version 2.0. It is just the language C# that didn't provide any syntax for it until version 4.



来源:https://stackoverflow.com/questions/9210483/covariance-also-in-3-5-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!