Skip to content

Pattern matching โ€“ Advanced

Advanced patterns include relational (<, >), logical (and/or/not), recursive and list patterns.

C# 9โ€“12 (2020โ€“2023)

static string Describe(int[] a) => a switch
{
[0, .. var rest] when rest.Length > 0 => "Starts with 0",
[> 10, ..] => "First > 10",
_ => "Other"
};