ReSharper 2024.1 Help

Code Inspection: Use preferred body style (convert to constructor or destructor with preferred body style)

Category

Syntax Style

ID

ArrangeConstructorOrDestructorBody

EditorConfig

resharper_arrange_constructor_or_destructor_body_highlighting

Default severity

Disabled

Language

C#

Requires SWA

No

Starting from C# 6.0, you can declare type 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 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 constructors and destructors. Accordingly, ReSharper suggests the quick-fix To expression body if a simple constructor is written with a block body:

public class MyClass { private string _name; public MyClass(string name) { _name = name; } }
public class MyClass { private string _name; public MyClass(string name) => _name = name; }
Last modified: 15 April 2024