这是什么(非lambda?)" =>" C#中的变量定义?

时间:2016-02-19 18:46:29

标签: c# c#-6.0

我正在查看C#的协议缓冲区和there's code like this

public sealed class FileDescriptor : IDescriptor
{
    // snip

    /// <value>
    /// The file name.
    /// </value>
    public string Name => Proto.Name;

    /// <summary>
    /// The package as declared in the .proto file. This may or may not
    /// be equivalent to the .NET namespace of the generated classes.
    /// </summary>
    public string Package => Proto.Package;

    // etc.

=> seems to be the lambda operator,但这看起来不像是一个lambda。这里发生了什么?

1 个答案:

答案 0 :(得分:2)

这是C#6表达身体的成员。它们允许您使用lambda语法指定属性实现。

此:

public string Name => Proto.Name;

相当于:

public string Name { get { return Proto.Name; } }