C# 6.0 版C# version 6.0 & Visual Studio 2015
=========================================
异常过滤器 Exception Filter
NameOf
字符串插值 (String Interpolation)
空操作符 ( ?. )
Index 初始化器
在Catch和Finally里使用Await
表达式方法体
using 静态类的方法可以使用 static using
自动属性初始化器
只读自动属性
=========================================
C# 在 3.0 版和 5.0 版对面向对象的语言添加了主要的新功能。With versions 3.0 and 5.0, C# had added major new features in an object-oriented language. 版本 6.0 随 Visual Studio 2015 一起发布,通过该版本,它不再推出主导性的杀手锏,而是发布了很多使得 C# 编程更有效率的小功能。With version 6.0, released with Visual Studio 2015, it would go away from doing a dominant killer feature and instead release many smaller features that made C# programming more productive. 以下介绍了部分功能:Here are some of them:
- 静态导入Static imports
- 异常筛选器Exception filters
- 自动属性初始化表达式Auto-property initializers
- Expression bodied 成员Expression bodied members
- Null 传播器Null propagator
- 字符串内插String interpolation
- nameof 运算符nameof operator
- 索引初始值设定项Index initializers
其他新功能包括:Other new features include:
- Catch/Finally 块中的 AwaitAwait in catch/finally blocks
- 仅限 getter 属性的默认值Default values for getter-only properties
这些功能每一个都很有趣。Each of these features is interesting in its own right. 但从整体来看,可以发现一个有趣的模式。But if you look at them altogether, you see an interesting pattern. 在此版本中,C# 消除语言样本,让代码更简洁且更具可读性。In this version, C# eliminated language boilerplate to make code more terse and readable. 所以对喜欢简洁代码的用户来说,此语言版本非常成功。So for fans of clean, simple code, this language version was a huge win.
除了发布此版本,他们还做了另一件事,虽然这件事本身与传统的语言功能无关。They did one other thing along with this version, though it's not a traditional language feature in itself. 他们发布了 Roslyn 编译器即服务。They released Roslyn the compiler as a service. C# 编译器现在是用 C# 编写的,你可以使用编译器作为编程工作的一部分。The C# compiler is now written in C#, and you can use the compiler as part of your programming efforts.