Expression-Bodied Members · TL;DR

1 min read
Mid-level7 min read
Rapid overview

TL;DR

An expression-bodied member replaces a block body { return …; } with => expression;. It is pure syntax: the compiler emits the same IL as the equivalent block body, so there is no runtime difference. C# 6 allowed it for methods, operators and read-only properties; C# 7.0 extended it to constructors, finalizers, get/set/init accessors and indexers. The traps: an expression-bodied property is computed on every access and has no storage (so => new List<T>() returns a new list each time, unlike the initializer { get; } = new List<T>()); async methods written as => OtherAsync() without await change exception and using behaviour; and long one-liners hurt readability. Use it for short, side-effect-free members: computed properties, simple forwarding, guard-and-assign accessors, and tiny constructors.