C#

C#

Made by DeepSource

Consider using if-else instead of a switch statement when having 2 or fewer cases CS-R1116

Anti-pattern
Minor

The primary use case of a switch statement is to handle different scenarios that cannot be easily handled using the traditional if-else statement. However, if a switch has 2 or fewer cases, consider falling back to the traditional if-else approach as it is easier to comprehend.

Bad Practice

switch (kind)
{
    case SyntaxKind.BinaryExpressionSyntax:
        // ...
        break;

    case SyntaxKind.IfStatementSyntax:
        // ...
        break;
}

Recommended

if (kind == SyntaxKind.BinaryExpressionSyntax)
{
    // ...
}
else if (kind == SyntaxKind.IfStatementSyntax)
{
    // ...
}