Skip to content

Instantly share code, notes, and snippets.

@carlrip
Created September 9, 2019 09:36
Show Gist options
  • Save carlrip/2044f306f79d452456335b9ae388852a to your computer and use it in GitHub Desktop.
Save carlrip/2044f306f79d452456335b9ae388852a to your computer and use it in GitHub Desktop.
C#8 switch expressions
public static string GetLevel(int level) =>
level switch
{
1 => "low",
2 => "medium",
3 => "high",
_ => throw new ArgumentException("invalid level"),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment