C# 14 · Records, classes and pattern matching
Add a method to an existing type
A static method in a static class, with this on its first parameter.
public static class StringExtensions
{
public static bool IsBlank(this string? s) => string.IsNullOrWhiteSpace(s);
}
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
- Choose a value with a switch expression
All records, classes and pattern matching commands · C# 14 cheatsheet