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

6) Graphics/rendering systems


Records: Ideal for Reference Types

  1) Domain Models:

public record Order(int OrderId, DateTime OrderDate, List<OrderItem> Items);

  2) Configuration Objects:

public record AppSettings(string ConnectionString, int MaxConnections);

   3) Immutable Data Transfer Objects (DTOs):

public record Customer(int CustomerId, string Name, Address Address);

   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

Popular posts from this blog

Upgrading to .NET8 from desktop versions 4.8.X

JSON Web Tokens

GHL > Set website so shorter URL address