Visual Studio - “{ }” settings

回眸只為那壹抹淺笑 提交于 2019-12-09 14:04:22

问题


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

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

But VisualStudio "helps" me with his 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

Any help appreciated!


回答1:


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.




回答2:


Tools -> Options ...

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




回答3:


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.



回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/2841887/visual-studio-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!