Events
17 Mar, 21 - 21 Mar, 10
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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:
dotnet_style_
.csharp_style_
.visual_basic_style_
.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
Value
For each language rule, you specify a value that defines if or when to prefer the style. Many rules accept a value of true
(prefer this style) or false
(do not prefer this style). Other rules accept values such as when_on_single_line
or never
.
Severity (optional in Visual Studio 2019 and later versions)
The second part of the rule specifies the severity level for the rule. In .NET 9 and later versions, the severity is always respected—that is, inside development IDEs and during command-line builds. In .NET 8 and earlier versions, this severity setting is only respected inside development IDEs, such as Visual Studio, and not during build.
If you're using the .NET 8 SDK or an earlier version and you want the severity to be respected at build time, you can do so in one of two ways:
<AnalysisLevelStyle>
property to 9.0
or higher, or to preview
.dotnet_diagnostic.<rule ID>.severity = <severity>
, for example, dotnet_diagnostic.IDE0040.severity = warning
. For more information, see severity level.Tip
Starting in Visual Studio 2019, you can configure code style rules from the Quick Actions light bulb menu after a style violation occurs.
Language and unnecessary code rules are further categorized into subcategories, such as expression-level preferences, code-block preferences, and modifier preferences.
using
directive preferencesThis.
and me.
preferencesvar
preferences.NET style rules (C# and Visual Basic):
C# style rules:
C# style rules:
C# style rules:
.NET style rules (C# and Visual Basic):
typeof
to nameof
(IDE0082)C# style rules:
new
expression (IDE0090)Create()
(IDE0303)Visual Basic style rules:
ByVal
(IDE0081)IsNot
operator) (IDE0084).NET style rules (C# and Visual Basic):
.NET style rules (C# and Visual Basic):
.NET style rules (C# and Visual Basic):
C# style rules:
C# style rules:
.NET style rules (C# and Visual Basic):
.NET style rules (C# and Visual Basic):
C# style rules:
not
operator) (IDE0083).NET style rules (C# and Visual Basic):
.NET style rules (C# and Visual Basic):
C# style rules:
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Events
17 Mar, 21 - 21 Mar, 10
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register now