Default branch is missing

CodeRush Classic shows the Default branch is missing code issue if a switch statement does not include the default branch, provided that the switch statement does not cover all available cases.

Fix

Add the default branch to the switch statement.

Purpose

Default branch is missing directs your attention to switch blocks without the default branch, because they usually denote incomplete code.

Example

private string _LastUsedSize;
public void GetChoice(int size)
{
    switch (size)
    {
        case 1:
            _LastUsedSize = "Small";
            break;
        case 2:
            _LastUsedSize = "Medium";
            break;
        case 3:
            _LastUsedSize = "Large";
            break;
    }
}

Fix:

private string _LastUsedSize;
public void GetChoice(int size)
{
    switch (size)
    {
        case 1:
            _LastUsedSize = "Small";
            break;
        case 2:
            _LastUsedSize = "Medium";
            break;
        case 3:
            _LastUsedSize = "Large";
            break;
        default:
            Console.WriteLine("Value is out of range");
            break;
    }
}