All rules
IDE0011Code block preferences MS default: Suggestion
Add braces
Require braces around the bodies of if, else, for, while, and similar statements.
Microsoft docsDescription
Controls whether braces are required even for single-line statement bodies. Enforcing braces avoids a class of bugs where an added second statement is silently excluded from a conditional block.
Why it matters
Single-statement blocks without braces are a common source of "goto fail"-style bugs when code is later edited.
Examples
Avoid
if (cart.IsEmpty)
return; Prefer
if (cart.IsEmpty)
{
return;
}Configurable options
Vote for the value each option should take in the generated .editorconfig.
csharp_prefer_braces default:
trueYour vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0