Combining multiple operators in curly braces

Is there a keyboard shortcut in Visual Studio 2010 (I also use ReSharper 6.1) that allows me to surround the selected block of text with curly braces? I tried "Surround With ..." (Ctrl + K, Ctrl + S), but there was no choice in the list for choosing curly braces as the surrounding element. A common example of using this is that I will have an if statement, for example:

if (conditional) statement1; // the rest of the program 

I will understand that there are some additional tasks that need to be performed inside the if statement, and I add them:

 if (conditional) statement1; statement2; statement3; // the rest of the program 

Then I remember that I need to wrap all the expressions in curly braces, and the code should look like this:

 if (conditional) { statement1; statement2; statement3; } // the rest of the program 

What I would like to do is simply select the three operators, and then press the shortcut key to wrap them with curly braces. What I'm actually doing is moving the cursor to the beginning of the line after the conditional expression, and then entering the character {and then deleting}, which ReSharper (uselessly) automatically inserts right after {, then moving the cursor to the end of the last block instruction and input} to complete the block.

+18
visual-studio-2010 curly-braces resharper curly-brackets
Apr 05 2018-12-12T00:
source share
1 answer

Select lines of code.

Press Ctrl EU (Surround with template) (or Ctrl Alt J for Intelli J).

Select option 7: {}.

It works for me.

+25
Apr 05 2018-12-12T00:
source share



All Articles