C# records, pattern matching and modern syntax, step by step
11 steps · about 4 h 10 min · Intermediate
- Tuples and types - Introductory tutorial - A tour of C# (interactive, Microsoft Learn, 30 min)
Start by creating tuples, records, structs and classes so you know the types that patterns will later inspect.
- C# record types (doc, Microsoft Learn, 25 min)
Next, learn what records add: value equality, positional records and deconstruction.
- Data collections - Introductory tutorial - A tour of C# (interactive, Microsoft Learn, 25 min)
It gives you the List<T> and bracket-initialiser basics that list patterns and collection expressions build on.
- Pattern matching overview - C# (doc, Microsoft Learn, 25 min)
Get the vocabulary of patterns, switch arms and when guards in one place before going into each kind.
- Pattern matching - A tour of C# (interactive, Microsoft Learn, 30 min)
Practise matching records with is and switch expressions on a hands-on bank-records example.
- C# Pattern Matching Explained (2026) (article, NDepend Blog, 25 min)
A second explanation with a cheat sheet that shows each pattern in copyable code, and says when not to use patterns.
- Using Modern SWITCH Syntax in C# (video, YouTube, 10 min)
A short video of switch expressions in action cements the shift from old switch statements.
- Property and positional patterns - C# (doc, Microsoft Learn, 20 min)
Records fit these recursive patterns best, so now go deeper into matching nested properties and deconstructed values.
- List and slice patterns - C# (doc, Microsoft Learn, 20 min)
Add the newest pattern family, which matches a sequence by its length and positions.
- What's new in C# 12 (doc, Microsoft Learn, 20 min)
Finish with primary constructors on any class and collection expressions with spread, which round out modern syntax.
- Patterns - Pattern matching using the is and switch expressions. - C# reference (reference, Microsoft Learn, 20 min)
Keep the full reference to hand to look up any pattern and its exact rules once you're writing your own code.