Code-style language and unnecessary code rules - .NET (original) (raw)

Code-style language rules affect how various constructs of .NET programming languages, for example, modifiers, and parentheses, are used.

This category also includes rules that identify parts of the code base that are unnecessary and can be refactored or removed. The presence of unnecessary code indicates one or more of the following problems:

The language rules fall into the following categories:

Option format

Many of the language rules have one or more associated options to customize the preferred style. For example, Use simple 'using' statement (IDE0063) has the associated option csharp_prefer_simple_using_statement that lets you define whether you prefer a using declaration or a using statement. The rule enforces whichever options you choose at a specified level, for example, warning or error.

Options for language rules can be specified in a configuration file with the following format:

option_name = value (Visual Studio 2019 and later)

or

option_name = value:severity

Tip

Starting in Visual Studio 2019, you can configure code style rules from the Quick Actions light bulb menu after a style violation occurs.

Rule index

Language and unnecessary code rules are further categorized into subcategories, such as expression-level preferences, code-block preferences, and modifier preferences.

using directive preferences

.NET style rules (C# and Visual Basic):

C# style rules:

Code-block preferences

C# style rules:

Expression-bodied members

C# style rules:

Expression-level preferences

.NET style rules (C# and Visual Basic):

C# style rules:

Visual Basic style rules:

Field preferences

.NET style rules (C# and Visual Basic):

Language keyword vs. framework types preferences

.NET style rules (C# and Visual Basic):

Modifier preferences

.NET style rules (C# and Visual Basic):

C# style rules:

New-line preferences

Null-checking preferences

C# style rules:

Parameter preferences

.NET style rules (C# and Visual Basic):

Parentheses preferences

.NET style rules (C# and Visual Basic):

Pattern-matching preferences

C# style rules:

Suppression preferences

.NET style rules (C# and Visual Basic):

This. and me. preferences

.NET style rules (C# and Visual Basic):

var preferences

C# style rules:

See also