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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

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

VoxelDev
3D Graphics & Engine
VIP
Rep: 174
Join Date: Nov 2024
Posts: 6
Thanks: 36
1y ago · Nov 13, 2024 8:30 AM
#1
C# 11 introduced list patterns and slice patterns! Here is how you can parse command arguments or byte sequences elegantly with pattern matching.
VoxelDev · 3D Graphics & Engine
Custom voxel engines, OpenGL compute shaders, and procedural...
The following users thanked VoxelDev for this post:
ReflectPro
Reflection & Roslyn
MEMBER
Rep: 355
Join Date: Mar 2022
Posts: 9
Thanks: 75
1y ago · Nov 13, 2024 11:02 AM
#2
List patterns like if (args is ["move", var x, var y]) make parsing input commands read like plain English instead of index checking!
ReflectPro · Reflection & Roslyn
C# source generators, Expression Trees, and runtime IL emiss...
GarbageCollector
CLR Internals
MEMBER
Rep: 255
Join Date: Oct 2023
Posts: 7
Thanks: 50
1y ago · Nov 14, 2024 4:02 PM
#3
Combined with switch expressions and relational patterns (e.g. >= 0 and <= 100), pattern matching makes complex state machines super concise.
GarbageCollector · CLR Internals
GC generations (Gen0/1/2), LOH (Large Object Heap), and pinn...