I'm having this code in a class
private string test;
public string Test
{
get => test;
set => test = value;
}
But the compiler won't let me compile. It says
CS1043 { or ; expected
CS1513 } expected
I'm using VS 2017 and targeting .NET FW 4.6 with a MVC 5 Project
Any idea why it isn't working?
The Syntax of expression body definition is, member => expression; where expression should be a valid expression and member can be any from above list of type members.
An expression-bodied method consists of a single expression that returns a value whose type matches the method's return type, or, for methods that return void , that performs some operation.
The expression-bodied syntax can be used when a member's body consists only of one expression. It uses the =>(fat arrow) operator to define the body of the method or property and allows getting rid of curly braces and the return keyword. The feature was first introduced in C# 6.
Yes, you can.
You have to set the compiler to version 7 in your project.
Project properties → (tab) Build → Advanced → Language version = C# 7.0
UPDATE BY @gsharp
check also your (NuGet) reference to the .NET Compiler platform Microsoft.Net.Compilers
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With