C#idiomatic C#
ide2003fundamentals/code-analysis/style-rules

Code analysis

Blank line required between block and subsequent statement (IDE2003)

Learn about code analysis rule IDE2003: Blank line required between block and subsequent statement

IDE2003 Style / Language rules (new-line preferences)
Applicable languages C# and Visual BasicOptions dotnet_style_allow_statement_immediately_after_block_experimental

Overview

This style rule enforces that there should be a blank line between a block statement and any subsequent statement at the same scope level. This improves code readability by visually separating different logical sections of code.

Options

Options specify the behavior that you want the rule to enforce. For information about configuring options, see Option format.

dotnet_style_allow_statement_immediately_after_block_experimental

Property Value Description
Option name dotnet_style_allow_statement_immediately_after_block_experimental
Option values true Allow subsequent statement to immediately follow block statement without a blank line in between
false Require a blank line between a block statement and the subsequent statement
Default option value true

Example

csharp
// dotnet_style_allow_statement_immediately_after_block_experimental = true
if (true)
{
    DoWork();
}
return;
csharp
// dotnet_style_allow_statement_immediately_after_block_experimental = false
if (true)
{
    DoWork();
}

return;

Suppress a warning

If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

csharp
#pragma warning disable IDE2003
// The code that's violating the rule is on this line.
#pragma warning restore IDE2003

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

ini
[*.{cs,vb}]
dotnet_diagnostic.IDE2003.severity = none

To disable all of the code-style rules, set the severity for the category Style to none in the configuration file.

ini
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-style.severity = none

For more information, see How to suppress code analysis warnings.

See also