ReSharper 2017.2 Help

Code Inspection: Redundant 'case' label

Empty case sections before the default case in a switch statement do not make any sense because code corresponding to their conditions will be executed in the default case anyway. ReSharper suggests removing such empty case sections:

Suboptimal codeAfter the quick-fix
switch (z) { case 1: Console.WriteLine("1"); break; case 2: default: Console.WriteLine("Not specified"); break; }
switch (z) { case 1: Console.WriteLine("1"); break; default: Console.WriteLine("Not specified"); break; }

Note that empty case sections before a non-empty case section are valid and mean that the code in the non-empty case section executes for all cases that go before it.

Last modified: 11 December 2017

See Also