Records and Record Structs - Use Cases
Record Structs: Ideal for Value Types.
Structs are stored on the stack.
1) Geometry:
Points, vectors, and geometric shapes are excellent candidates for record structs.
2) Color Representations:
RGB, HSV, or CMYK color models.
3) IP Address
4) Immutable Data Transfer Objects (DTOs):
public record struct Address(string Street, string City, string ZipCode);
5) Latitude and longitude location
Points, vectors, and geometric shapes are excellent candidates for record structs.
2) Color Representations:
RGB, HSV, or CMYK color models.
3) IP Address
4) Immutable Data Transfer Objects (DTOs):
public record struct Address(string Street, string City, string ZipCode);
5) Latitude and longitude location
6) Graphics/rendering systems
Records: Ideal for Reference Types
1) Domain Models:
2) Configuration Objects:
3) Immutable Data Transfer Objects (DTOs):
4) Event Sourcing:
public record UserRegisteredEvent(string UserId, string Email, DateTime RegistrationDate);
5) API Responses:
public record ApiResponse(bool Success, string Message, object Data);
6) Logging:
public record LogEntry(DateTime Timestamp, string LogLevel, string Message);
7) Caching Keys:
public record CacheKey(string UserId, string Operation);
Comments
Post a Comment