Skip to content

Switch Expressions (C# 8+)

Switch expressions provide a more concise syntax.

int day = 2;
string dayType = day
switch
{
1 or 7 => "Weekend",
_ => "Weekday"
};
Console.WriteLine(dayType);
Terminal window
dotnet run
Terminal window
Weekday