Add/Remove Block Delimiters
- 2 minutes to read
Purpose
The Add Block Delimiters Code Formatter is used when you need to extend a single-line loop body or if block and make it multi-line. In this case, you need to put the block into delimiters. You may also need this Code Formatter because sometimes block delimiters increase code readability even if they are optional.
The Remove Block Delimiters Code Formatter is useful when you have reduced a block to a single line and want to remove unnecessary braces.
In both cases, you don’t have to manually locate the start and end of the required code block — this Code Formatter automatically inserts or removes delimiters at the correct locations.
Availability
Available when the caret is at the beginning of the first statement within an if, else or loop statement.
Usage
Place the caret at the beginning of the single-line block as shown in the code below.
Note
The blinking cursor shows the caret’s position at which the Code Formatter is available.
if (condition)│MessageBox.Show("The condition is true");
- Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
- Select Add Block Delimiters or Remove Block Delimiters from the menu.
After execution, the Code Formatter puts a single-line block into braces so that you can extend it or removes the braces around the block.
if (condition) {
MessageBox.Show("The condition is true");
}
Note
This feature is available as a part of Code Cleanup.