How to edit result of "for + tab" shortcut in Visual Studio?

Viewed 36

When I write "for" and click tab in Visual Studio (2019), the IDE generates this code:

for (int i = 0; i < length; i++)
{

}

But I want the IDE to generate this:

for (int i = 0; i < length; i++){

}

How to move open curly bracket one level up in code generation?

1 Answers

From the Tools menu, select the Options command. In the pop-up that appears, expand the Text Editor item in the list on the left hand side, as follows: Text Editor -> C# -> Code Style -> Formatting and select the New Lines item.

Then, in the list displayed, scroll to find the Place open brace on new line for control blocks item and uncheck that, as shown here (a preview of the format style will be shown in the lower part of the pop-up):

enter image description here

Click on the OK button, and you're done.

Related