C# records, pattern matching and modern syntax, step by step

11 steps · about 4 h 10 min · Intermediate

  1. 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.

  2. C# record types (doc, Microsoft Learn, 25 min)

    Next, learn what records add: value equality, positional records and deconstruction.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. List and slice patterns - C# (doc, Microsoft Learn, 20 min)

    Add the newest pattern family, which matches a sequence by its length and positions.

  10. 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.

  11. 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.