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.
(I do not have ReSharper installed)
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 .
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.
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.
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.
Found the setting that caused this:
Options > Text Editor > C# > Formatting > Wrapping > Leave statements and member declarations on the same line
must be checked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With