协方差 也在 3.5 / 2.0 中吗?
奇怪的问题...
我已经从示例中实现了协方差。
我的目标固件是 4.0。
然而 。我想看看它是否在 3.5 /2 上失败 ->但它不会。
不可能,因为协方差是从 FW4.0 开始的。
更改为 3.0 后,我构建并查看:(+不会在运行时失败)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
框架 3 支持协方差,但编译器中未实现。您正在使用编译器 4 定位框架 3。Eric
Lippert 博客文章中提到了这一点,我会看看是否能找到它。
编辑
为了进一步澄清:公共语言运行时和 C# 编译器 (csc.exe) 是两个不同的事情。协变和逆变是在 CLR 2.0 版本中引入的。它们直到版本 4 才被引入 C#。您正在使用编译器 4 构建版本 3 IL,这就是它起作用的原因。
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.
CLR 从 2.0 版开始就支持协变和逆变泛型类型参数。只是 C# 语言直到版本 4 才提供任何语法。
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.