public class MyClass
{
public string DeviceCommands { get; set; } = "DeviceCommands";
}
I have 30 errors on this kind of lines...
public class MyClass
{
public string DeviceCommands { get; set; } = "DeviceCommands";
}
I have 30 errors on this kind of lines...
.NET 4.6.2 is a framework version, not a language version. To be able to do that line you must be using C# 6 or newer. If you are compiling with C# 6 you would be allowed to use that syntax in a .NET 2.0 project.
If you are using Visual Studio 2015 or newer you are using C# 6 or newer.
If you are using Visual Studio 2015 and are still getting errors there is some other problem with your code that you are not showing us.
UPDATE:
If you are using VS2015 and are getting a error that says
Error CS8026: Feature 'auto property initializer' is not available in C# 5. Please use language version 6 or greater.
That means in your project properties -> Build -> Advanced screen you set the language version manually to 5 or lower instead of default.
Setting it back to default
will fix the problem.
The syntax you have are Auto Property Initializers.
It has nothing to do with the .NET Version. It is a language feature from C# 6.0
.
You need the the roslyn compiler plattform to make this work.
If you can not support C# 6.0
, you could do it the old way:
public class MyClass
{
public string DeviceCommands { get; set; };
public MyClass()
{
DeviceCommands = "DeviceCommands";
}
}