C# Pattern Matching: is, switch, Property, and List Patterns
Pattern matching lets you inspect and destructure values in a single expression. If you are looking for a practical answer to "pattern matching switch c#", the short version is that it gives you a cleaner way to express branching logic than a long chain of if statements.
Quick answer: use
iswhen you need to test and capture a value, and use aswitchexpression when several patterns map to different results.
It started in C# 7 with is type patterns and has expanded across every subsequent version: C# 8 added property patterns, C# 9 added relational and logical patterns, C# 10 added extended property patterns, and C# 11 added list patterns.
All patterns work in both is expressions and switch expressions.
On this page
- Type Pattern: is T variable
- Constant Pattern
- Relational Pattern (C# 9+)
- Logical Patterns: and, or, not (C# 9+)
- Property Pattern
- Extended Property Pattern (C# 10+)
- Positional Pattern
- List Pattern (C# 11+)
- FAQ
- What is the difference between switch statements and switch expressions?
- When should I use pattern matching instead of if statements?
- Real-World Example: Discount Calculator
Type Pattern: is T variable
Test the type of an object and bind it to a new variable in one step. No cast required.
Constant Pattern
Match a specific value: useful for null checks and literal comparisons.
Relational Pattern (C# 9+)
Compare values without writing the variable name twice.
Logical Patterns: and, or, not (C# 9+)
Combine patterns with and, or, and not keywords.
Property Pattern
Inspect properties without extracting them to variables first.
Extended Property Pattern (C# 10+)
Navigate nested properties using . inside the pattern.
Positional Pattern
Deconstructs an object and matches on the deconstructed values. Works with records and types that have a Deconstruct method.
List Pattern (C# 11+)
Match the structure and contents of a list or array.
FAQ
What is the difference between switch statements and switch expressions?
Use a switch statement when you need imperative control flow. Use a switch expression when you want to return a value concisely from a single expression.
When should I use pattern matching instead of if statements?
Pattern matching is a strong fit when the decision is based on type, shape, or multiple related conditions.
Real-World Example: Discount Calculator
Take It Further

The book that turns good C# developers into great ones. Written by Stack Overflow's #1 contributor.
C# in Depth: 4th Edition · Jon Skeet
Get it on Amazon →As an Amazon Associate I earn from qualifying purchases.
Related Articles
Switch expressions in C# 8.0+ provide concise pattern matching that returns a value directly. They replace verbose switch statements and eliminate break.
Learn how a C# record differs from a class: value equality, immutability, with expressions, inheritance, and record struct examples.
The ?? operator returns the left operand if not null, otherwise the right. Use ??= to assign a default value only when the variable is null in C#.
Nullable reference types in C# 8.0+ make nullability explicit to prevent NullReferenceException. Enable with the Nullable enable setting in your project.