Skip to content

Instantly share code, notes, and snippets.

@christiannagel
Created May 5, 2018 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiannagel/7b03df00a5559bb40e346300ca6b3a77 to your computer and use it in GitHub Desktop.
Save christiannagel/7b03df00a5559bb40e346300ca6b3a77 to your computer and use it in GitHub Desktop.
Pattern matching with C# 7
public void PatternMatchingWithIsOperator(object o)
{
if (o is 42)
{
}
if (o is Person p)
{
}
if (o is var v1)
{
}
}
public void PatternMatchingWithSwitchStatement(object o)
{
swtich (o)
{
case 42:
break;
case Person p when p.FirstName == "Katharina":
break;
case Person p:
break;
case var v:
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment