Back to course

Pattern Matching

C# Zero to Hero: Comprehensive Programming Masterclass

Pattern Matching

Pattern matching is a way to test expressions and perform actions if the test is successful.

Switch Expression Pattern

csharp string result = obj switch { int i => $"It's an integer: {i}", string s => $"It's a string: {s}", _ => "Unknown type" };