Interview frequency: …
Short answer
Records are designed for immutable value objects (Immutability), provide automatic value-based equality, and support non-destructive copying with the with expression.
Explanation
Ordinary Classes use Reference Equality, so two objects are different even if all their properties match. Records compare values automatically and generate Equals, GetHashCode, and formatted ToString methods. Positional Records also provide concise one-line definitions such as public record UserDto(int Id, string Name); with init-only properties by default.
Code example
public record Point(int X, int Y);
var p1 = new Point(1, 2);
var p2 = new Point(1, 2);
Console.WriteLine(p1 == p2); // True (Compare by value)
var p3 = p1 with { Y = 5 }; // Non-mutating copyCommon mistakes
- Using ordinary Classes for DTOs and DDD value objects, then having to implement Equals and GetHashCode manually.