Skip to content

Instantly share code, notes, and snippets.

@fjod
Created October 2, 2019 19:25
Show Gist options
  • Save fjod/b61698c1d6c345f63b92076e78c3fd9e to your computer and use it in GitHub Desktop.
Save fjod/b61698c1d6c345f63b92076e78c3fd9e to your computer and use it in GitHub Desktop.
C# 8 switch with true
return true switch
{
_ when a == b => 1,
_ when foo == "foobar" => 2,
_ when someFunction() => 3,
_ => 4,
};
https://www.reddit.com/r/csharp/comments/dccpx9/using_pattern_matching_to_replace_lengthy_ifelse/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment