Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Visual Studio to automatically include curly brackets in C# code?

After namespace, class, struct, enum, for, foreach, while, switch, do, using, unchecked and at the beginning of methods, shouldn't Visual Studio automatically include curly brackets? How to activate this feature?

like image 288
Jader Dias Avatar asked Mar 01 '10 12:03

Jader Dias


People also ask

How do I add curly brackets in Visual Studio?

Ctrl + Shift + Enter = Insert blank line below the current line. Ctrl + Space = Autocomplete using IntelliSense. Alt + Shift +arrow keys( ← , ↑ , ↓ , → ) = Select custom part of the code. Ctrl + } = Match curly braces, brackets.

How do you use curly brackets in C?

In programming, curly braces (the { and } characters) are used in a variety of ways. In C/C++, they are used to signify the start and end of a series of statements. In the following expression, everything between the { and } are executed if the variable mouseDOWNinText is true. See event loop.

How do you put curly brackets in?

On English keyboards, the open bracket and close bracket are on the same key as the [ and ] (square bracket) keys, located near the Enter key. To get a curly bracket, press and hold the Shift key, then press the { or } key.

How do you align brackets in Visual Studio?

If you have Power Commands installed you can then go to the Tools->Options->Power Commands and make sure "Format Document on Save" is selected. Whenever you save the edited file the Curly Braces will be auto aligned.


1 Answers

With Resharper curly closing bracket adds by itself (either right away or after pressing enter). I think it's also the case for non-resharped Visual Studio but not 100% sure about that. Only opening bracket you have to write by yourself.

Currently Resharper 5.0 is free (as long as it's in beta/night build status), you just have to reinstall it every 20-30 days (but you would want to do it anyway since they tend to fix/add things). I can't code without Resharper anymore :-) It's so much time saver! Not sure what i will do when it's no longer beta ;/

Edit:

With Resharper you can even get IDE to use braces or not to use them in some cases (where it's possible). Check out this link about code formatting in Resharper.

like image 52
MadBoy Avatar answered Sep 19 '22 02:09

MadBoy