ReSharper 2018.1 Help

Code Inspection: Use preferred body style (convert to local function with preferred body style)

Starting from C# 6.0, you can declare function members using expression bodies, which look very similar to lambda expressions. You can use expression-bodied methods and properties to further simplify the syntax of simple implementations.

If you prefer to stick to either expression-bodied or block-bodied implementations for simple function members, ReSharper lets you configure your preferences separately for different kinds of members and maintain the consistency of your preferences throughout your codebase.

For example, let's select Expression body as the preferred style for local functions. Accordingly, ReSharper suggests the quick-fix To expression body if a simple local function is written with a block body:

Suboptimal codeAfter the quick-fix
public int LocalFunction() { int Sum(int x, int y) { return x + y; } return Sum(42, 55); }
public int LocalFunction() { int Sum(int x, int y) => x + y; return Sum(42, 55); }
Last modified: 20 August 2018

See Also