case
labels are redundant if they fallthrough to default
case CS-R1107C# allows you to chain one or more cases in a switch statement. This is particularly useful if you have code that can be reused for multiple cases. However, these cases become redundant if the controller eventually falls through them and reaches the default
case. In such scenarios, such cases are redundant and can be safely removed.
switch (node.Kind())
{
SyntaxKind.ArrayCreationExpression:
// ...
break;
SyntaxKind.MethodDeclaration:
// ...
break;
// These cases eventually lead to the `default` case.
SyntaxKind.ClassDeclaration:
SyntaxKind.StructDeclaration:
default:
// ...
break;
}
switch (node.Kind())
{
SyntaxKind.ArrayCreationExpression:
// ...
break;
SyntaxKind.MethodDeclaration:
// ...
break;
// Cases `ClassDeclaration` and `StructDeclaration` are removed.
default:
// ...
break;
}