Created
May 5, 2018 21:53
-
-
Save christiannagel/7b03df00a5559bb40e346300ca6b3a77 to your computer and use it in GitHub Desktop.
Pattern matching with C# 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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