Pattern Matching
is, switch and property patterns test shape and type in one step.
Example
object o = 42;
if (o is int n && n > 40) Console.WriteLine($"big int {n}");
string d = o switch { int i when i < 0 => "neg", int i => "int", string => "text", _ => "other" };
Console.WriteLine(d);Exercise
Type test.
o int n
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.