C# 4.0 向后兼容 C# 2.0 吗?
我可以知道 C# 4.0 和 C# 2.0 有什么区别吗? C# 4.0 向后兼容 C# 2.0 吗?
我可以说 C# 4.0 是 C# 2.0 的超集(就像 C++ 与 C 一样)吗?
谢谢。
May I know what is the difference between C# 4.0 and C# 2.0? Is C# 4.0 backward compatible to C# 2.0?
Can I say that C# 4.0 is a superset of C# 2.0 (just like what C++ is to C)?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
C# 4.0几乎向后兼容以前的版本,但有很少有重大变化。对于大多数普通代码,您不会注意到这些重大更改。
对于 C# 4 中的新功能,您可以查看 Wikipedia 文章,其中有相当多的内容很好的总结和例子。关键点是:
另请记住,中间还有另一个版本 - C# 3.0。这里最重要的添加之一是 LINQ 以及为此而添加的所有功能。 C# 2.0 和 3.0 之间的差异比 C# 3.0 和 4.0 之间的差异大得多。
顺便说一句,正如您在问题中暗示的那样,并非所有有效的 C 代码都是有效的 C++。请参阅此处:
C# 4.0 is nearly backwards compatible with previous versions but there are a few breaking changes. For most ordinary code you won't notice these breaking changes.
For the new features in C# 4 you can check out the Wikipedia article which has quite a good summary with examples. The key points are:
Also remember that there was another version in between - C# 3.0. One of the most important additions here is LINQ and all the features added to make it possible. The difference between C# 2.0 and 3.0 is much greater than the difference between C# 3.0 and 4.0.
By the way, not all valid C code is valid C++ as you implied in your question. See here:
与之前的版本一样,有一些微妙的重大变化。问题在于,C# 4 由于协变/逆变引入了一种新的有效转换类型。这意味着一些以前不适用的方法现在适用于特定的调用。下面是一些对 C# 4 和 C# 2 / 3 都有效的代码:
在 C# 4 中,这将打印“Derived” - 在 C# 2 和 3 中,它将打印“Base”。
C# 1 和 2 之间也出现了同样的问题,其中委托实例表达式允许非泛型协变和逆变。
任何新的转换都必然会产生此类问题。然而,根据我的经验,这些事情不太可能真正引起问题。
此外,C# 4 以稍微不同的方式处理锁定和类似字段的事件 - 同样,这不会影响大多数代码,但值得了解。 Chris Burrows 在其博客中发布了关于这些更改的系列文章 。
There are some subtle breaking changes, as there have been in previous versions. The problem is that C# 4 introduces a new type of valid conversion due to covariance/contravariance. This means that some methods which would previously have not been applicable are now applicable for a particular call. Here's some code which is valid for both C# 4 and C# 2 / 3:
In C# 4, this will print "Derived" - in C# 2 and 3 it will print "Base".
The same sort of issue occurred between C# 1 and 2, where delegate instance expressions allowed nongeneric covariance and contravariance.
Any new conversions are pretty much bound to create this sort of issue. In my experience, however, these things are unlikely to actually cause a problem.
Additionally, C# 4 handles locking and field-like events in a slightly different way - again, this won't affect most code, but it's worth knowing about. Chris Burrows has a series of articles on the changes in his blog.
是的,他们过去常常这样做。
C# 4.0 中的新增功能
Yes, they used to do it like that.
Whats new in C# 4.0
是的,
C# 2.0 的所有功能仍然保留在 C# 4.0 中,但是,版本 4 中的新功能显然在版本 2 中没有。
您在 C# 2.0 中编写的所有内容都可以在 C# 4.0 中使用。
但显然相反的做法是行不通的......
YES,
All the features of C# 2.0 are in still in C# 4.0, HOWEVER, there are new features in version 4 that are obviously not in version 2.
Everything you wrote in C# 2.0 will work in C# 4.0.
But obviously the opposite would not work.....
C# 2.0 添加了许多功能,如下所示:
所以请查看上面的链接以了解新功能..
There are many featured added from C# 2.0 as follow :
so please review the above links to know the new features ..
不过,请注意 - 留意 thinks 被弃用 - 例如 ADO.Net 中的 OracleClient...
Martin
编辑 - 是的,Simon 说得有道理...我真的在谈论 .Net。对不起...
A word of caution though - watch out for thinks getting deprecated - OracleClient in ADO.Net for instance...
Martin
EDIT - Yeah, Simon's got a point there... I'm really talking about .Net. Sorry...