Reputation: 1501
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
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.
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
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):
Options:
Upvotes: 5
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
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
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