Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code: How change c# case statement bracket indent format style?

I am writing c# code in visual studio code and I didn't install any formatter or beautifier, so I guess "C# for Visual Studio Code (Powered by OmniSharp)" is using a default formatter (whatever that is).

I like to use brackets in case statements, however, the formatter is indenting the bracket as follows.

switch (name)
{
    case "Bob":
        {
            break;
        }

    case "Jim"
        {
           break;
        }
}

How can I change the formatter so that it doesn't indent the brackets in the case statements?

like image 617
user1164199 Avatar asked Sep 18 '25 08:09

user1164199


1 Answers

In visual studio code:

  • create file with name .editorconfig
  • add the line csharp_indent_case_contents_when_block = false

In visual studio: tools > options > text editor > C# > Code Style > Formatting > Indentation > uncheck "indent case contents (when block) Options menu image

like image 88
Sean Avatar answered Sep 19 '25 23:09

Sean