ReSharper 2016.1 Help

Code Inspection: Convert to property with expression body

The expression-bodied properties, introduced in C# 6.0 are both more concise and readable. Therefore, as soon as ReSharper encounters a get-only property whose get accessor returns a single expression, it suggests to convert it to an expression-bodied property.

Here is an example of a quick-fix suggested by this inspection:

Suboptimal codeAfter the quick-fix
private string _name; public int NameLength { get { return string.IsNullOrEmpty(_name) ? 0 : _name.Length; } }
private string _name; public int NameLength => string.IsNullOrEmpty(_name) ? 0 : _name.Length;

See Also

Last modified: 19 August 2016