visual-studio Visual Studio - "{ }" 设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2841887/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:59:15  来源:igfitidea点击:

Visual Studio - "{ }" settings

visual-studiocode-formatting

提问by Xorty

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

说真的,我不知道该谷歌什么。事情就是这样,我喜欢这种类似 java 的代码编写:

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 :/)

但是 VisualStudio 用他自己的“风格”“帮助”了我,我不喜欢而且我无法改变(经过相当长时间的绝望检查所有设置:/)

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

我使用的是 MS Visual Studio 2010 专业版

Any help appreciated!

任何帮助表示赞赏!

回答by

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

转到工具>选项>文本编辑器>[语言,即:C#]>代码样式>格式>新行

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

您可以在此处设置大括号的新行选项。

See the image below for more clarification.

请参阅下图以获得更多说明。

menu

菜单

回答by jessicah

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

文本编辑器> C#>格式>>大括号的换行选项

  • Uncheck Place open brace on new line for control blocks.
  • Probably want to uncheck put else on newlineas well.
  • 取消选中Place open brace on new line for control blocks
  • 可能也想取消选中put else on newline

回答by Guffa

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

这是针对 Visual Stuio 2008 的,所以我不确定它在 VS 2010 中是否完全相同:

Go to the Toolsmenu and open Options. Make sure that the Show all settingscheckbox is checked. Open the Text Editornode and then the node for the language you want to change the setting for. Open the Formattingnode and select the New Linesnode. Here you can change when new lines are added to the code.

转到Tools菜单并打开Options. 确保Show all settings选中该复选框。打开Text Editor节点,然后打开要更改设置的语言的节点。打开Formatting节点并选择New Lines节点。您可以在此处更改何时将新行添加到代码中。

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

安装 Visual Studio 后,我进入那里并取消选中该New Lines部分中的每个选项。

回答by Ms01

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.

值得知道的是,Steve Horn(和其他人)的答案甚至适用于其他语言,因为它们似乎没有相同的设置布局。我按照他的帖子中所述进行了更改,它也适用于我的 C++ 项目。