A good strategy is to type the brackets in pairs first:
public void foo()
{
}
Then add the content:
public void foo(List<int> values)
{
foreach ()
{
}
}
There are keyboard shortcuts that allow you to do this faster. Try typing foreach
then press Tab twice.
If you still manage to get confused it might be because your methods are too long. You can refactor your code into smaller methods. Use the "Extract Method" refactoring tool to help you do this.
You may also want to occasionally "Format Document". This will line up the braces for you, and indent your code. This will make it more obvious which braces match up.
You might also want to consider installing a third party extension such as Resharper.