if
-else
instead of a switch
statement when having 2 or fewer cases CS-R1116The 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.
switch (kind)
{
case SyntaxKind.BinaryExpressionSyntax:
// ...
break;
case SyntaxKind.IfStatementSyntax:
// ...
break;
}
if (kind == SyntaxKind.BinaryExpressionSyntax)
{
// ...
}
else if (kind == SyntaxKind.IfStatementSyntax)
{
// ...
}