【问题标题】:Using "=>" operator in C# [duplicate]在 C# 中使用“=>”运算符 [重复]
【发布时间】:2019-01-24 15:51:33
【问题描述】:

我从 Internet 获得了一个代码,其中包含以下代码行

protected override Freezable CreateInstanceCore() => new ExponentialDoubleAnimation();

我没有在 Visual Studio 中安装此版本的 C#。所以这显示了“缺少;”的错误。 谁能告诉我这行代码在 c# 5 及以下的类似代码是什么?

【问题讨论】:

  • @CamiloTerevinto 我已经编辑了您的重复列表,因为表达式主体成员不是 lambda 表达式。
  • @ZoharPeled 谢谢,我忘了删除错误的

标签: c# c#-7.0


【解决方案1】:

C#6(当然还有更高版本)支持expression body methods。它相当于:

protected override Freezable CreateInstanceCore() 
{
    return new ExponentialDoubleAnimation();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 2020-04-29
    • 1970-01-01
    • 2013-06-04
    相关资源
    最近更新 更多