C# 6.0 => 运算符

标签 c#

这个问题在这里已经有了答案:





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/

相关文章:

c# - VS2013 C# 函数声明 => 符号

c# - 如何将 Hex 转换为 Unicode?

c# - 如何限制可观察集合数据绑定(bind)列表框中的项目数量?

c# - 序列化(TextWriter,“对象”)与序列化(XmlWriter,“对象”)

c# - 在 Windows 8 中使用 C# 设置菜单 Flyout 背景颜色

c# - 扩展 WPF 应用程序

c# - !IsPostBack 和 Asp.Net 中的刷新之间的区别

c# - 如何从 Internet 获取 DateTime(外部资源 - 不是来自服务器)

c# - 如何在任何分辨率下找到屏幕的中心

c# - DataGridView 在键入时更新单元格值