Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
| Property | Value |
|---|---|
| Rule ID | IDE2005 |
| Title | Blank line not allowed after conditional expression token |
| Category | Style |
| Subcategory | Language rules (new-line preferences) |
| Applicable languages | C# |
| Options | csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental |
Note
This rule is experimental and subject to change or removal.
Overview
This style rule enforces that there should not be a blank line after the question mark (?) or colon (:) tokens in conditional (ternary) expressions. These operators should be immediately followed by their respective expressions without blank lines.
Options
Options specify the behavior that you want the rule to enforce. For information about configuring options, see Option format.
csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental
| Property | Value | Description |
|---|---|---|
| Option name | csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental |
|
| Option values | true |
Allow a blank line after the token in a conditional expression |
false |
Require statement to immediately follow token in a conditional expression | |
| Default option value | true |
Example
// csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true
int result = IsTrue ?
ComplexExpr1() :
ComplexExpr2();
// csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false
int result = IsTrue
? ComplexExpr1()
: ComplexExpr2();
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.
#pragma warning disable IDE2005
// The code that's violating the rule is on this line.
#pragma warning restore IDE2005
To disable the rule for a file, folder, or project, set its severity to none in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.IDE2005.severity = none
To disable all of the code-style rules, set the severity for the category Style to none in the configuration file.
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-style.severity = none
For more information, see How to suppress code analysis warnings.