开发者

Visual Studio - "{ }" settings

Seriously, I don't know what to google. Here's the thing, I like this Java-like code writing:

if (condition =开发者_运维知识库= true) {
   doSomeStuff();
}

But VisualStudio "helps" me with its own "style", which I don't like and I am unable to change (after rather big time of desperate checking all settings :/)

if (condition == true)
{
  DoStuff();
}

I obviously want the "{" char to be in same line where condition is ...

I am using MS Visual Studio 2010 professional.


Go to Tools > Options > Text Editor > [Language, i.e.: C#] > Code Style > Formatting > New Lines

This is where you can set your new line options for braces.

See the image below for more clarification.

Visual Studio - "{ }" settings


Tools -> Options ...

alt text http://img6.imageshack.us/img6/158/capturejo.png


Text Editor > C# > Formatting > New Lines > New line options for braces

  • Uncheck Place open brace on new line for control blocks.
  • Probably want to uncheck put else on newline as well.


This is for Visual Stuio 2008, so I'm not sure that it's exactly the same in VS 2010:

Go to the Tools menu and open Options. Make sure that the Show all settings checkbox is checked. Open the Text Editor node and then the node for the language you want to change the setting for. Open the Formatting node and select the New Lines node. Here you can change when new lines are added to the code.

After installing Visual Studio I go in there and uncheck every option in the New Lines section.


Worth knowing is that Steve Horn's (and others) answer works even for other languages as they seem to appear to not have the same settings-layout. I did the changes as described in his post and it worked for my C++ projects as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜