【问题标题】:What's wrong with this arrow symbol? [duplicate]这个箭头符号有什么问题? [复制]
【发布时间】:2018-06-05 23:46:21
【问题描述】:

我在 c# 中有以下文件,我正在使用 VS 2013,但我卡在“=>”符号上,VS 总是要求输入“;”在以下文件中的“=>”符号之后:

namespace GlobomanticsElectricCompany.BillProcessor.Models
{
    public class ContactInfo
    {
        public string Line1 { get; set; }
        public string Line2 { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Zip { get; set; }
        public string Phone { get; set; }
        public string Email { get; set; }
        public string CityStateZip => $"{City}, {State} {Zip}";
    }
}

我应该怎么做才能让VS识别那个“=>”符号?

【问题讨论】:

  • 你需要 C# > 6 才能使用=>
  • 字符串插值也会有类似的问题。
  • 要更改 C# 版本,请转到项目,右键单击,属性,在按钮的构建选项卡下,您将找到高级,打开它并选择正确的语言版本
  • @Nekeniehl C# 6 在 VS2013 中不可用。
  • @CamiloTerevinto 我的错误,对不起。这确实是一个纯 C# 问题。

标签: c#


【解决方案1】:

我最近遇到了这个问题;我不相信 => 语法在该版本的 Visual Studio 中有效。尝试像这样定义它:

    public string CityStateZip
    {
        get
        {
            return City + " , " + State + " " + Zip;
        }
    }

【讨论】:

  • 您可能需要在其中添加一些额外的空格,或者使用旧的 String.Format
  • 该功能称为 Expression bodied members,可从 c# 6 获得。
  • @HansKesting 谢谢你,错过的傻事
  • 谢谢尼克,它就像一个魅力。 :-)
猜你喜欢
  • 2020-06-17
  • 1970-01-01
  • 1970-01-01
  • 2016-05-31
  • 1970-01-01
  • 2011-02-06
  • 2013-06-15
  • 2018-04-06
相关资源
最近更新 更多