ReSharper 2018.2 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 code

After 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;

Last modified: 19 October 2018

See Also