C#8.0新特性
只读成员 private struct Point { public Point( double x, double y) { X = x; Y = y; } private double X { get ; set ; } private double Y { get ; set ; } private readonly double Distance => Math.Sqrt(X * X + Y * Y); public override readonly string ToString() => $ " ({X}, {Y}) is {Distance} from the origin " ; } View Code 使用readonly修饰tostring方法,表示它不可修改 默认接口方法 /// <summary> /// 默认接口方法 /// </summary> private interface IWork { public void Work() { Console.WriteLine( " Work " ); } } 现在可以在接口中定义默认的方法,而不是只能申明void Work(); 更多的模式匹配 使用switch表达式的模式匹配 public enum Rainbow { Red, Orange, Yellow, Green, Blue, Indigo,