Aller au contenu

Expressions switch (C# 8+)

Les expressions switch offrent une syntaxe plus concise.

int day = 2;
string dayType = day switch
{
1 or 7 => "Weekend",
_ => "Weekday"
};
Console.WriteLine(dayType);
Fenêtre de terminal
dotnet run
Fenêtre de terminal
Weekday