How to get curly braces autocompletion in Visual Studio 2012. C #

10,846

Solution 1

See this question on StackOverflow: Curly braces autocomplete in Visual Studio 2012

Basically either of the following free add-ins should do the trick:

Additionally you may find that code snippets can help in certain situations, e.g. typing if followed by Tab will insert a boilerplate if statement and allow you to quickly enter the condition before hitting Enter to place the cursor inside. Similarly typing ctr and pressing Tab will do the same for the class constructor. There is not one for methods included by default but it is possible to create custom snippets.

Solution 2

I use ReSharper which adds this behavior. I believe Visual Studio is relying on the user to enter the } to trigger formatting:

Options

Share:
10,846
Chris_45
Author by

Chris_45

Updated on September 18, 2022

Comments

  • Chris_45
    Chris_45 over 1 year

    In moste IDEs you can set so if you type for example>

    if(isTrue) { //and when you hit enter here you get the } automatically
    

    But I have not found where you get this behavior in VS Options. Is there an addon for this?

    • James P
      James P about 11 years
      Is it not just easier to do if followed by [Tab] which creates the whole block for you?
    • James P
      James P about 11 years
      I should clarify that I'm talking about code snippets. Also, pressing [Enter] after typing the condition puts the cursor inside the if statement.
    • Chris_45
      Chris_45 about 11 years
      Yes you are right in that case. But if you want to write a constructor or something else public MyConstructor() {//...
  • Chris_45
    Chris_45 about 11 years
    And opens up with Microsoft Visual Studio Version Selector
  • James P
    James P about 11 years
    @Chris_45: Can you explain what you mean?