Expression bodied members in constructors and get-set properties in C# 7.0
February 6, 2018 Leave a comment
Expression bodied members were introduced in C# 6 for methods and properties. This feature has been extended to constructors and getters/setters in C# 7.0.
Here’s an example:
public class Dog
{
private string name;
public Dog(String name) => this.name = name;
public string NameFormatted
{
get => name.ToUpper();
set => name = value.ToUpper();
}
public string Name
{
get => name;
}
}
View all various C# language feature related posts here.