In C# 9, we got `record` (which was a reference type). In C# 10, we get `record struct`.
Syntax
public record struct Point(int X, int Y);
Performance Characteristics
Because it’s a struct, `Point` is allocated on the stack. No GC pressure! Because it’s a record, you get:
- Value-based equality (automatically implemented)
- Deconstruction
- `ToString()` formatting
Be careful: structs are copied by value. If your record struct is large (more than 16 bytes), passing it around might be slower than passing a reference. For simple data like Coordinates, Vector3, or ComplexNumber, `record struct` is the perfect tool.
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.