C# 14 · Records, classes and pattern matching
Require properties at creation
Force callers to set a property, and make it settable only during initialization.
public class User
{
public required string Email { get; init; }
public string? Nickname { get; set; }
}
More records, classes and pattern matching commands
- Declare an immutable data type
- Copy a record with changes
- Declare a class with a primary constructor
- 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