#1,218 – C# 6.0 – Using Expression-Bodied Property Getters
November 4, 2014 5 Comments
In addition to using expression-body definitions for method bodies in C# 6.0, you can use an expression-body definition to implement the getter of a read-only auto-property.
For example:
public string Name { get; protected set; } public int Age { get; set; } public string BackwardsName => new string(Name.Reverse().ToArray());
The presence of the expression-body definition tells the compiler that this is a property with a getter, rather than a field.
Pingback: Dew Drop – November 4, 2014 (#1891) | Morning Dew
This is absolutely beautiful.
I agree!
This seems to be inconsistent! getter-only properties should have a readonly backing field (https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6#getter-only-auto-properties). So how does that work with those lambdas?
not working for me.. getting error