Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Visual Studio to add break lines in switch-case statements

Is there a way to prevent Visual Studio (2010) "Format document" menu to format the switch-case statements as the following:

When I write my code like:

switch (value) {
    case "1": mode = Mode.One; break;
    case "2": mode = Mode.Two; break;
}

And then hit "Format document", Visual Studio adds break lines:

switch (value) {
    case "1":
        mode = Mode.One;
        break;
    case "2":
        mode = Mode.Two;
        break;
}

I have looked into the Formatting section of VS Options, but I can't find anything relevant.

Options>Formatting

(I do not have ReSharper installed)

like image 521
Otiel Avatar asked Mar 14 '13 16:03

Otiel


People also ask

Can switch case write without break?

Without break , the program continues to the next labeled statement, executing the statements until a break or the end of the statement is reached. This continuation may be desirable in some situations. The default statement is executed if no case constant-expression value is equal to the value of expression .

Is Break mandatory in switch statement C#?

The break in switch statement is used to terminate the current sequence. The default statement is optional and it can be used anywhere inside the switch statement.

What happens if you dont give break in switch case?

Break will return control out of switch case.so if we don't use it then next case statements will be executed until break appears. The break statement will stop the process inside the switch.

What happens if break statements are not included inside each case block?

If we do not use break statement at the end of each case, program will execute all consecutive case statements until it finds next break statement or till the end of switch case block.


1 Answers

Found the setting that caused this:

Options > Text Editor > C# > Formatting > Wrapping > Leave statements and member declarations on the same line must be checked.

Options dialog

like image 115
Otiel Avatar answered Oct 02 '22 22:10

Otiel