Skip to content

Latest commit

 

History

History
52 lines (42 loc) · 1.25 KB

RR0214.md

File metadata and controls

52 lines (42 loc) · 1.25 KB

Convert 'switch' expression to 'switch' statement

Property Value
Id RR0214
Title Convert 'switch' expression to 'switch' statement
Syntax switch expression
Span switch keyword
Enabled by Default

Usage

Before

return dayOfWeek switch
{
    DayOfWeek.Monday => 1,
    DayOfWeek.Tuesday => 2,
    DayOfWeek.Wednesday => 3,
    DayOfWeek.Thursday => 4,
    DayOfWeek.Friday => 5,
    _ => throw new Exception(),
};

After

switch (dayOfWeek)
{
    case DayOfWeek.Monday:
        return 1;
    case DayOfWeek.Tuesday:
        return 2;
    case DayOfWeek.Wednesday:
        return 3;
    case DayOfWeek.Thursday:
        return 4;
    case DayOfWeek.Friday:
        return 5;
    default:
        throw new Exception();
}

See Also

(Generated with DotMarkdown)