使用lambda运算符的C#方法声明
在研究过程中,我在MSDN网站上偶然发现了以下代码块:使用lambda运算符的C#方法声明,c#,lambda,C#,Lambda,在研究过程中,我在MSDN网站上偶然发现了以下代码块: public static Complex operator +(Complex c1, Complex c2) => new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary); // Override ToString() to display a complex number // in the traditional format: public over
public static Complex operator +(Complex c1, Complex c2) =>
new Complex(c1.real + c2.real, c1.imaginary + c2.imaginary);
// Override ToString() to display a complex number
// in the traditional format:
public override string ToString() => $"{this.real} + {this.imaginary}";
在某些情况下,这是定义简单方法的一种非常有用的方法,但我不记得在任何地方见过对它的描述。我试图在C#5.0语言规范中搜索此方法声明语法的描述,但什么也找不到。我在网络搜索中也没有找到任何东西
两个问题:
它是在C#6中添加的,你可以在新编译器的官方Github上阅读。它是在C#6中添加的,你可以在新编译器的官方Github上阅读。这是一个C#6功能。啊,这解释了很多。我很惊讶在网上找不到任何关于它的信息。我想我的搜索引擎fu需要改进。这是C#6的功能。啊,这解释了很多。我很惊讶在网上找不到任何关于它的信息。我想我的搜索引擎需要改进。