c# 一些操作符 【=>】

115 阅读1分钟

=>

  • 读作:goes to
  • 用于:
    1. 将属性设置为 只读 并 赋值
    2. lamda 表达式
    public class Man : IPerson {     
        public string Sex => "男";
    }

等价于

    public class Man : IPerson {     
        public string Sex { get; } = "男";
    }

delegate int Method(int a, int b);

Method m += (a ,b) => a + b;\
Console.WriteLine(m(2, 3));