C# 14 · Records, classes and pattern matching

Match the shape of a list

Match arrays and lists by length and contents.

var result = numbers switch
{
    [] => "empty",
    [var only] => $"one: {only}",
    [var first, .., var last] => $"{first}..{last}"
};

Official C# 14 documentation

More records, classes and pattern matching commands

All records, classes and pattern matching commands · C# 14 cheatsheet

Was this page helpful?