系列目录    【已更新最新开发文章,点击查看详细】 <https://www.cnblogs.com/SavionZhang/p/11229640.html>
C# 7.1 是 C# 语言的第一个点版本(更新版本)。 它标志着该语言发布节奏的加速。 理想情况下,可以在每个新功能准备就绪时更快推出新功能。 C#
7.1 增加了将编译器配置为匹配特定语言版本的功能。 从而可以分别制定有关升级语言版本的决策和有关升级工具的决策。

C# 7.1 增加了语言版本选择
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/configure-language-version>
配置元素、三个新的语言功能和新的编译器行为。

最后,编译器有 -refout 和 -refonly 两个选项,可用于控制引用程序集生成
<https://docs.microsoft.com/zh-cn/dotnet/csharp/whats-new/csharp-7-1#reference-assembly-generation>


若要使用单点版本中的最新功能,需要配置编译器语言版本
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/configure-language-version>
并选择版本。
01 异步 main 方法 异步 Main 方法使你能够在 Main 方法中使用 await 关键字。 在过去,需要编写: static int
Main() {return DoAsyncWork().GetAwaiter().GetResult(); }
现在,可以编写:
static async Task<int> Main() {
// DoAsyncWork,包括其等待表达式: return await DoAsyncWork(); }
如果程序不返回退出代码,可以声明返回 Task
<https://docs.microsoft.com/zh-cn/dotnet/api/system.threading.tasks.task> 的 Main
 方法:
static async Task Main() { await SomeAsyncMethod(); }
如需了解更多详情,可以阅读编程指南中的异步 Main
<https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/main-and-command-args/index>
 一文。
02 默认文本表达式 默认文本表达式是针对默认值表达式的一项增强功能。 这些表达式将变量初始化为默认值。 过去会这么编写: Func<string, bool
> whereClause =default(Func<string, bool>); 现在,可以省略掉初始化右侧的类型: Func<string, bool
> whereClause =default;
若要详细了解此增强功能,可以参阅 C# 编程指南中的默认值表达式
<https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/statements-expressions-operators/default-value-expressions>
一文。

此增强功能也会更改某些default 关键字
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/keywords/default>
 的分析规则。
03 推断元组元素名称 此功能是对 C# 7.0 中引入的元组功能一次小型增强。 在初始化元组时,许多时候,赋值操作右侧的变量名与用于元组元素的名称相同:
int count = 5; string label = "Colors used in the map"; var pair = (count:
count, label: label);
元组元素的名称可通过在 C# 7.1 中初始化元组时使用的变量进行推断:
int count = 5; string label = "Colors used in the map"; var pair = (count,
label);// element names are "count" and "label"
若要详细了解此功能,可以参阅元组 <https://docs.microsoft.com/zh-cn/dotnet/csharp/tuples>一文。
04 泛型类型参数的模式匹配 自 C# 7.1 起,is 和 switch 类型模式的模式表达式的类型可能为泛型类型参数。 这可能在检查 struct 或 
class 类型且要避免装箱时最有用。 05 引用程序集生成 有两个新编译器选项可生成仅引用程序集:-refout
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/compiler-options/refout-compiler-option>
 和 -refonly
<https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/compiler-options/refonly-compiler-option>
 。 链接的文章详细介绍了这些选项和引用程序集。   系列目录    【已更新最新开发文章,点击查看详细】
<https://www.cnblogs.com/SavionZhang/p/11229640.html>

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信