Robert Fraser Robert Fraser - 3 months ago 30
C# Question

Visual Studio : Automatically insert a space after typing if(

We have a code style checker that's run before every check-in that requires that C# if statements be formatted like:

if (condition)


However, my muscle memory has already developed for typing:

if(condition)


Is there any way to get Visual Studio 2010 to automatically insert that space if I type the if without it? I know you can set it that when you paste code, it will automatically do this, but not while typing. Thanks!

Answer

Tools > Options > Text Editor > C# > Formatting > Spacing

Then check/tick Insert space after keywords in control flow statements, which is listed under the Set other spacing options sub group.

Win.