C# 8.0 的新特性
目录 可空引用类型(Nullable reference types) 异步流(Async streams) 范围和下标类型(Ranges and indices) 模式匹配表达式(Switch expressions ) Switch表达式 Property patterns Positional patterns 非空判断 Tuple patterns 递归模式语句(recursive patterns) 使用VS2019体检C#8.0新功能: 编辑.csproj文件,添加如下代码 <PropertyGroup> <LangVersion>preview</LangVersion> </PropertyGroup> 回到顶部 可空引用类型(Nullable reference types) 引用类型将会区分是否可空,可以从根源上解决 NullReferenceException。 #nullable enable void M(string? s) { Console.WriteLine(s.Length); // 产生警告:可能为 null if (s != null) { Console.WriteLine(s.Length); // Ok } } #nullable disable 回到顶部 异步流(Async streams) 考虑到大部分 Api