JetBrains Rider 2024.1 Help

Code Inspection: Redundant empty switch section

Category

Redundancies in Code

ID

RedundantEmptySwitchSection

EditorConfig

resharper_redundant_empty_switch_section_highlighting

Default severity

Warning

Language

C#

Requires SWA

No

In C#, you do not have to include the default section in switch statements. If no case sections were executed, and there is no default section specified, control is transferred outside a switch statement.

JetBrains Rider considers the empty default branch redundant and suggests removing it to improve the code readability.

switch (x) { case 1: Console.WriteLine(x); break; /*...*/ default: break; }
switch (x) { case 1: Console.WriteLine(x); break; /*...*/ }
Last modified: 17 April 2024