Expression Bodied MethodsI like to break down my code down to short methods. Quite short. So I often have one-liner methods. In Nancy.Linker I had this for instance:
With C# 6 I can make this even shorter because methods that consist of just one expression, can be implemented as just that - one expression .... with a fat arrow in front of it. Like so:
Expression Bodied PropertiesI didn't have an opportunity to use any expression bodies properties in Nancy.Linker, but I want to mention them anyway.
Just as single expression methods can be changed to be a fat arrow followed by the expression so can getter only properties that have just one expression in the getter. Note what I said there: Getter only properties can be expression bodied. Properties with setters cannot ... but ... think about it ... what would it mean to set a property consisting of only an expression? There is nothing there to assign to.
Seeing that expression bodied properties are getter only, it stands to reason that you don't have to state the 'get'.
As an example an expression bodied property looks like this:
Do I Like These?Yes :-)
I like them because they cut down on boilerplate.