C#8.0 新语法特性 ??= [..] 电脑版发表于:2021/4/26 14:40 # C#8.0 部分语法特性 #### Null 合并赋值 ```c# List<int> numbers = null; int? i = null; numbers ??= new List<int>(); numbers.Add(i ??= 17); //i null 赋值为17 numbers.Add(i ??= 20); //i 为17 值不改变 Console.WriteLine(string.Join(" ", numbers)); // output: 17 17 Console.WriteLine(i); // output: 17 ``` ####索引和范围 ```c# string a1 = "123456"; string s = a1[..]; //123456 string s1 = a1[..3]; //123 string s2 = a1[3..]; //456 string s3 = a1[2..4]; //34 ```