如何将 VisualStudio 设置为使用 K & R 样式括号?

我真的不喜欢这种格式:

Class AwesomeClass
{
private static void AwesomeMethod()
{


}


}

我能让它像这样格式化我的代码吗?

Class AwesomeClass {


private static void AwesomeMethod() {


}
}
26846 次浏览

Go to Tools > Options > Text Editor > C# > Formatting > New Lines.

In recent version of Visual Studio (at least 2017):

Tools > Options > Text Editor > C# > Code Style > Formatting > New Lines

Then just uncheck every option you see there.

Tools > Options

Check "Show all settings"

Text Editor > C# > Formatting > New Lines

Uncheck the settings for where you want no extra newline added. Personally I always uncheck all items in this category.

Tools->Options->Text Editor->C/C++->Formatting->New Lines

change all values to

"Keep on the same line, but add a space before"

then select a block and reformat with Ctrl + K, Ctrl + F

enter image description here