C#4.0向下兼容C#2.0? [英] Is C# 4.0 backward compatible to C# 2.0?
问题描述
我可以知道C#4.0和C#2.0之间有什么区别吗?是C#4.0向下兼容C#2.0?
我可以说C#4.0是C#2.0的超集(就像C ++对C)
感谢。
与以前的版本兼容,但有几个突变。对于大多数普通代码,您不会注意到这些突变的更改。
对于C#4中的新功能,您可以查看维基百科文章,其中有很多例子。重点是:
- 动态成员查询
- 协变和逆变通用类型参数
- 使用COM时可选的参数关键字
- 可选参数和命名参数
- 索引属性
还要记住,在中间有另一个版本 - C#3.0。这里最重要的补充之一是LINQ和所有的功能添加,使其成为可能。 C#2.0和3.0之间的差异远远大于C#3.0和4.0之间的差异。
所有有效的C代码是有效的C ++,如你暗示在你的问题。请参见此处:
在严格的数学意义上,C不是C ++的子集。有些程序是有效的C但不是有效的C ++,甚至几种方法编写代码在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.
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:
- Dynamic member lookup
- Covariant and contravariant generic type parameters
- Optional ref keyword when using COM
- Optional parameters and named arguments
- Indexed properties
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:
In the strict mathematical sense, C isn't a subset of C++. There are programs that are valid C but not valid C++ and even a few ways of writing code that has a different meaning in C and C++.
这篇关于C#4.0向下兼容C#2.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!