Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用lambda运算符的C#方法声明_C#_Lambda - Fatal编程技术网

使用lambda运算符的C#方法声明

使用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

在研究过程中,我在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 override string ToString() => $"{this.real} + {this.imaginary}";
在某些情况下,这是定义简单方法的一种非常有用的方法,但我不记得在任何地方见过对它的描述。我试图在C#5.0语言规范中搜索此方法声明语法的描述,但什么也找不到。我在网络搜索中也没有找到任何东西

两个问题:

  • 这种方法声明语法在哪个版本的C#中可用
  • 该语法在语言规范中的何处描述

  • 它是在C#6中添加的,你可以在新编译器的官方Github上阅读。

    它是在C#6中添加的,你可以在新编译器的官方Github上阅读。

    这是一个C#6功能。啊,这解释了很多。我很惊讶在网上找不到任何关于它的信息。我想我的搜索引擎fu需要改进。这是C#6的功能。啊,这解释了很多。我很惊讶在网上找不到任何关于它的信息。我想我的搜索引擎需要改进。