C# 14 · Records, classes and pattern matching
Choose a value with a switch expression
A compact switch that returns a value, with a default.
string label = score switch
{
>= 90 => "A",
>= 80 => "B",
_ => "C"
};
More records, classes and pattern matching commands
- Declare an immutable data type
- Copy a record with changes
- Declare a class with a primary constructor
- Require properties at creation
- Customize an auto-property
- Test and unpack a type
All records, classes and pattern matching commands · C# 14 cheatsheet