Created
June 13, 2017 10:31
-
-
Save PradeepLoganathan/9b5b1cf83e3310560b50fe9e927c5123 to your computer and use it in GitHub Desktop.
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
//Const pattern check | |
public static void IsPattern(object o) | |
{ | |
if (o is null) Console.WriteLine("it's a const pattern"); | |
//... | |
} | |
public static void IsPattern(object o) | |
{ | |
if (o is null) throw new ArgumentNullException(nameof(o)); | |
if (o is 42) Console.WriteLine("it's 42"); | |
//... | |
} | |
//Type Pattern | |
if (o is int i) Console.WriteLine($"it's a type pattern | |
if (o is Person p) Console.WriteLine($"it's a person: {p.FirstName}"); | |
//var pattern | |
if (o is var x) Console.WriteLine($"it's a var pattern with the type {x?.GetType()?.Name}"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment