3

From a similar question asked before, it is known that the preferred way of indenting nested using statements is (which is pre-Visual Studio 2015's default):

using (var enumerator1 = list1.GetEnumerator())
using (var enumerator2 = list2.GetEnumerator())
{
    // Use enuemrator1 and enumerator2 here
}

However, I found the behaviour was changed in Visual Studio 2015, when I type the following:

using (var enumerator1 = list1.GetEnumerator())

and hit , the cursor is indented on the second line:

using (var enumerator1 = list1.GetEnumerator())
    ‸ // Text caret appears here instead of at the same level of
     // indent of the previous line

How can I get the old behaviour back and what is the rationale of changing this behaviour?

Community
  • 1
  • 1
rexcfnghk
  • 14,435
  • 1
  • 30
  • 57

1 Answers1

5

If you have ReSharper, you need to untick the setting named Indent nested "using" statements.

It can be found in the Code Editing section => C# => Formatting Style => Other.

ReSharper Option


Even if the option is unticked, the caret will still appears with an indentation. However, once you make a newline, ReSharper will format your using block correctly:

ReSharper formatting kicking in

Pierre-Luc Pineault
  • 8,993
  • 6
  • 40
  • 55