C#

C#

Made by DeepSource

Empty default label without a comment is redundant CS-R1022

Anti-pattern
Major

The default case in a switch is executed when none of the provided cases match. An empty default case without a user comment is redundant. Either add a user comment to indicate to the reader and the analyzer that all the possible cases have been covered, or, consider throwing a NotImplementedException to indicate that some cases are yet to be handled.

Bad Practice

switch (choice)
{
    case 'y':
        //
        break;
    case 'n':
        //
        break;
    default:
        break;
}

Recommended

// Alternative 1: Adding a user comment
switch (ch)
{
    case 'y':
        //
        break;
    case 'n':
        //
        break;
    default:
        // All cases are handled
        break;
}

// Alternative 2: Throwing `NotImplementedException` exception
switch (ch)
{
    case 'y':
        //
        break;
    case 'n':
        //
        break;
    default:
        throw new NotImplementedException();
        break;
}

Reference