How can I set Visual Studio to use K&R style bracketing?

C#Formatting

C# Problem Overview


I really don't like this style of formatting:

Class AwesomeClass
{
    private static void AwesomeMethod()
    {

    }

}

Can I make it format my code like this?

Class AwesomeClass {

    private static void AwesomeMethod() {

    }
}

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

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.

Solution 3 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncoryView Question on Stackoverflow
Solution 1 - C#Matt GreerView Answer on Stackoverflow
Solution 2 - C#GuffaView Answer on Stackoverflow
Solution 3 - C#mahendra230668View Answer on Stackoverflow