Search code examples
c#visual-studio-2008formattingresharper

Visual Studio adding space after if-statements


Sometimes (but not always!?) when I paste or end a line with a semi-colon, Visual Studio will add a space after the if statement! For example, when pasting, this

if()

will turn into this:

if (condition)

and, when completing a line, this

if(condition)
    DoSomething()

will turn into this:

if (condition)
    DoSomething();

Having to constantly delete this space (sometimes twice!) is driving me absolutely Bonkers! It seems to happen with if and while but not for.

I cannot find anything relating to this in the VS options. I do have Resharper installed, but it is set to not add the space automatically: (image of my resharper settings)

Why is Visual Studio punishing me?


Solution

  • In the Visual Studio options, under Text Editor / C# / Formatting / Spacing, in the "Set other spacing options" part, there's an option for "Insert space after keywords in control flow statements".

    I suspect you'll find you've got that checked, and you don't want it to be. (I have it checked deliberately :)