Mid-levelMid (3–6 yrs)C#.NETMicrosoftAtlassian
Records and immutability
How do C# records help with domain modeling and DTOs?
Answers use simple, clear English.
Quick interview answer
Records provide value-based equality, concise init syntax, and with-expressions for non-destructive mutation. They are ideal for DTOs, events, and immutable domain values. Prefer record class for reference semantics with value equality, or record struct when you need stack-friendly value types.
Detailed answer
Records provide value-based equality, concise init syntax, and with-expressions for non-destructive mutation. They are ideal for DTOs, events, and immutable domain values. Prefer record class for reference semantics with value equality, or record struct when you need stack-friendly value types.
Code example
public sealed record OrderCreated(Guid OrderId, decimal Total, DateTimeOffset At);
var updated = order with { Total = order.Total * 1.18m };midseniorfull-stack#oop#dto