2

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).

Is there something wrong with my syntax?

Calum
  • 1,889
  • 2
  • 18
  • 36
Peter Richter
  • 755
  • 1
  • 6
  • 15
  • 7
    This is a feature of C# 6, not .NET Framework. – Dmitry Sep 23 '15 at 18:33
  • It looks like there's an outdated version of an extension that implements some C# 6 features for VS 2013: http://stackoverflow.com/questions/27093908/how-to-enable-c-sharp-6-0-feature-in-visual-studio-2013 If you want the full compiler, you'll have to upgrade to VS 2015 – ps2goat Sep 23 '15 at 18:39

1 Answers1

3

You may be targeting .NET 4.6 but auto-initializers is a C# 6 feature rather than a feature of the Framework.

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536