S3458 — Empty "case" clauses that fall through to the "default" should be omitted

Language
C#
Type
Code smell
Severity
Minor
Tags
finding, clumsy

Why is this an issue?

Empty case clauses that fall through to the default are useless. Whether or not such a case is present, the default clause will be invoked. Such cases simply clutter the code, and should be removed.

Noncompliant code example


switch(ch)
{
  case 'a' :
    HandleA();
    break;
  case 'b' :
    HandleB();
    break;
  case 'c' :  // Noncompliant
  default:
    HandleTheRest();
    break;
}

Compliant solution


switch(ch)
{
  case 'a' :
    HandleA();
    break;
  case 'b' :
    HandleB();
    break;
  default:
    HandleTheRest();
    break;
}

↑ Back to top