Home / Forums / Pattern Matching Mastery in C# 11 & 12: List Patterns & Property Patterns [Discussion #2]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

Pattern Matching Mastery in C# 11 & 12: List Patterns & Property Patterns [Discussion #2]

ImGuiStyler
ImGui Animation Specialist
MEMBER
Rep: 210
Join Date: Mar 2024
Posts: 22
Thanks: 55
5y ago · Feb 22, 2021 8:45 PM
#1
C# 11 introduced list patterns and slice patterns! Here is how you can parse command arguments or byte sequences elegantly with pattern matching.
ImGuiStyler | Clean Custom UI Controls & Easing
The following users thanked ImGuiStyler for this post:
SecurityAudit
AppSec & Code Auditor
MEMBER
Rep: 135
Join Date: Jan 2025
Posts: 28
Thanks: 29
5y ago · Feb 22, 2021 11:56 PM
#2
List patterns like if (args is ["move", var x, var y]) make parsing input commands read like plain English instead of index checking!
SecurityAudit | Secure C++ Architecture & Boundary Auditing
DevDan
.NET Core & Cloud
MEMBER
Rep: 324
Join Date: Feb 2021
Posts: 16
Thanks: 65
5y ago · Feb 24, 2021 3:56 AM
#3
Combined with switch expressions and relational patterns (e.g. >= 0 and <= 100), pattern matching makes complex state machines super concise.
DevDan · .NET Core & Cloud
Writing clean C# code and microservices since .NET Core 2.1....