Expression-Bodied Members¶
Expression-bodied members are a shorter way to write methods and properties
when they only have one line of code. Instead of { }
, you use =>
(fat arrow).
Expression-Bodied Lambda
:
Expression-Bodied Methods
:
When a method only returns a single value, you can skip { } and return
.
Expression-Bodied Properties
:
Shortcut for read-only properties
(only get, no set)
Expression-Bodied Indexers
:
Used when a class acts like an array.
Expression-Bodied Constructors
:
Short way to set a value in a constructor
Same as: