C# 14 · Records, classes and pattern matching
Declare a class with a primary constructor
Put constructor parameters on the type declaration and use them in members.
public class Greeter(string name)
{
public string Greet() => $"Hello, {name}!";
}
More records, classes and pattern matching commands
- Declare an immutable data type
- Copy a record with changes
- Require properties at creation
- Customize an auto-property
- Choose a value with a switch expression
- Test and unpack a type
All records, classes and pattern matching commands · C# 14 cheatsheet