ReSharper 2024.1 Help

Code Inspection: Some values of the enum are not processed inside switch statement and are handled via default section

Category

Potential Code Quality Issues

ID

SwitchStatementHandlesSomeKnownEnumValuesWithDefault

EditorConfig

resharper_switch_statement_handles_some_known_enum_values_with_default_highlighting

Default severity

Hint

Language

C#

Requires SWA

No

When using a switch statement with an enum, it is not required to have a case statement for each enum value — if some values do not have cases, they will be handled in the default section.

This might be intended by the author to handle some unimportant values. But this might be also a consequence of adding a new value to the enum and forgetting to update the switch accordingly.

ReSharper flags such switch statements as potential issues and suggests generating case statements for unhandled values.

enum TestEnum { A, B } class Program { void Test(TestEnum testEnum) { switch (testEnum) { case TestEnum.A: Console.WriteLine("A"); break; // case E.B will be handled in the default section default: Console.WriteLine("X"); break; } } }
Last modified: 15 April 2024