Events
Mar 17, 11 PM - Mar 21, 11 PM
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.
Property | Value |
---|---|
Rule ID | IDE0011 |
Title | Add braces |
Category | Style |
Subcategory | Language rules (code-block preferences) |
Applicable languages | C# |
Options | csharp_prefer_braces |
This style rule concerns the use of curly braces { }
to surround code blocks.
Use the following option to specify whether curly braces are preferred or not, and if preferred, whether only for multi-line code blocks.
For more information about configuring options, see Option format.
Property | Value | Description |
---|---|---|
Option name | csharp_prefer_braces | |
Option values | true |
Prefer curly braces even for one line of code |
false |
Prefer no curly braces if allowed | |
when_multiline |
Prefer curly braces on multiple lines | |
Default option value | true |
// csharp_prefer_braces = true
if (test) { this.Display(); }
// csharp_prefer_braces = false
if (test) this.Display();
// csharp_prefer_braces = when_multiline
if (test) this.Display();
else { this.Display(); Console.WriteLine("Multiline"); }
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 IDE0011
// The code that's violating the rule is on this line.
#pragma warning restore IDE0011
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.IDE0011.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.
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Events
Mar 17, 11 PM - Mar 21, 11 PM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register now