简体   繁体   English

自动属性初始化程序不起作用?

[英]Auto-property initializers won't work?

I'm trying to use auto-property initializers , like so: 我正在尝试使用自动属性初始化程序 ,如下所示:

class Class1
{
    public string Auth { get; set; } = "BlahBlah";
}

However, when I build, I get the following error: 但是,在构建时,出现以下错误:

Invalid token '=' in class, struct, or interface member declaration 类,结构或接口成员声明中的无效令牌“ =”

This is in Visual Studio 2013, using Target Framework .NET 4.6 (which is the version which introduced auto-property initializers). 这是在Visual Studio 2013中使用的是Target Framework .NET 4.6(该版本引入了自动属性初始化程序)。

Is there something wrong with my syntax? 我的语法有问题吗?

您可能以.NET 4.6为目标,但是自动初始化器是C#6的功能,而不是Framework的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM