C#

C#

Made by DeepSource

A switch statement having only a default case is redundant CS-R1124

Anti-pattern
Major

A switch statement allows you to handle various cases for a given input. The default case is executed when none of the specified cases match the given input and can be considered as a fallback case. However, a switch statement with just a default case effectively achieves nothing and should be refactored by adding more cases or by using an alternate flow statement such as an if statement.

Bad Practice

switch (i)
{
    default:
        // ...
        break;
}

Recommended

switch (i)
{
    case 0:
        // ...
        break;

    case 1:
        // ...
        break;

    default:
        // ...
        break;
}