C#

C#

Made by DeepSource

Nested switch statements CS-W1001

Bug risk
Minor

Nested switch statements can affect code readability, refactoring and can cause additional bugs to creep in. Therefore, it is recommended that you refactor your code accordingly, i.e., either avoid nested switches or move the inner switch to a separate method/lambda.

Bad Practice

switch (outerValue)
{
    case someValue:
        switch (innerValue)
        {
            case 3.14:
                Console.WriteLine("pi");
                break;

            // Additional cases
        }
        break;
}

Recommended

Func<X, Y> someLambda ...

switch (outerValue)
{
    case someValue:
        someLambda(innerValue);
        break;
}

Reference