JetBrains Rider
 
Get JetBrains Rider
Get your hands on the new features ahead of the release by joining the Early Access Program for Rider 2025.1! Learn more

Code Syntax Style: Braces for Single Nested Statements

Last modified: 26 May 2024

C# specification allows you to safely omit braces around single nested statements under some parent statements, for example if-else, foreach, and so on. However, code style guidelines may differ in this regard. Some consider the braces here as a requirement, some consider them redundant. Whatever style you prefer, the important thing is to have consistent use of braces throughout your codebase. With JetBrains Rider, you can define your preference for using braces after each type of code block and enforce this style.

JetBrains Rider also provides multiple formatting rules for braces layout (whitespaces, tabs, and new lines). You can configure these rules in Rider settings CtrlAlt0S, for example, go to the Editor | Code Style | C# page and check the preferences on the Braces layout tab.

JetBrains Rider helps you apply braces style in the existing code and takes your preferences into account when it produces new code with code completion and code generation features, applies code templates and performs refactorings.