5uperdan
5uperdan

Reputation: 1501

What methods are there to identify brace/ curly bracket pairs in the Visual Studio IDE?

Coming from a VB background I've wondered why I have as much difficulty structuring my c# as i do. I realised yesterday what one of the core differences between the two languages is. Take this example

If True Then
    While True
        For i As Integer = 0 To 10
            c = a + b
        Next
    End While
End If

It's clear where the scope of each block ends because

  1. Matching indentation
  2. Inside the IDE, clicking on an opening or closing brace highlights the other.
  3. Closing statement matches opening statement (eg. While/ End While)

For the same code in c#

if (true) 
{
    while (true) 
    {
        for (int i = 0; i <= 10; i++) 
        {
            c = a + b;
        }
    }
}

1 and 2 still apply but we've lost 3.

  1. Matching indentation
  2. Inside the IDE, clicking on an opening or closing statement highlights the other.

It seems like there should be features like automatic colour coding of braces.

What other strategies are available for keeping track of matching pairs of braces?

Upvotes: 2

Views: 1369

Answers (4)

Marc Gravell
Marc Gravell

Reputation: 1062820

I use the VSCommands "Code Block End Tagger" (note: despite not being mentioned on the website, it is also available for VS 2013):

enter image description here

Options:

enter image description here

Upvotes: 5

vallabha
vallabha

Reputation: 385

To identify the closing brace of a particular opening brace or vise verse. you can just place the cursor at the starting/ending of the brace then VS will automatically highlight the ending/starting brace. But with a very light color. To get notify easily you can change the color in

Tools ->Options ->Environment ->Fonts and Colors ->Display items ->Brace Matching(Rectangle) ->Item foreground, Select the color you want.

Upvotes: 3

CodeCaster
CodeCaster

Reputation: 151594

There are various Visual Studio extensions that add lines and coloring for code blocks, like Productivity Power Tools and Indent Guides

Of course, when you need this, you may have too many levels of indentation and might want to review and refactor your code.

Upvotes: 4

mp3ferret
mp3ferret

Reputation: 1193

Put the cursor over a brace and hit CTRL+]. This will take yo to the matching brace.

Make sure you are consistent with your indents.

Upvotes: 4

Related Questions