这个问题在这里已经有了答案:
What is the => assignment in C# in a property signature
(7 个回答)
5年前关闭。
我正在使用 Visual Studio 2013。我在 github 中找到了一个项目,该项目正在使用 Visual Studio 2015。我正在尝试编译它,但使用 vs2013 时出现错误
Invalid token ';' in class, struct, or interface member declaration
这里的代码:
private readonly Log _log;
public Log Log => _log; // What => Operator is doing ? Pointer ?
是的,
=>
有哪些新功能? C# [6.0]
中的运算符?有没有办法在 vs2013 中使用 C# 6.0?
最佳答案
编写只读属性是一个较短的版本。
public Log Log => _log;
等于
public Log Log { get { return _log; } }
但我不知道在旧版本中无法使用此功能。
关于C# 6.0 => 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40286062/