C# Record vs Class: Equality, Immutability, Constructors, and with
Records (C# 9+) are a special kind of reference type designed for immutable data models. The compiler automatically generates value-based equality (Equals, GetHashCode, ==), a ToString() that lists all properties, and Deconstruct (things you'd write by hand for a plain class).
Use records for DTOs, value objects, domain events, and any type whose identity is defined by its data rather than its reference.
On this page
Record vs Class: Quick Answer
Use a record when equality should be based on the object's data, such as a DTO or value object. Use a class when object identity, mutable state, or reference-based behavior matters. Both are reference types unless you choose record struct.
| Feature | record | class |
|---|---|---|
| Equality by default | Value-based | Reference-based |
| Concise immutable model | Yes, with init properties | Must be designed explicitly |
| Non-destructive updates | with expression | Usually manual copying |
| Best fit | DTOs, value objects, messages | Services, entities, mutable state |
Defining a Record: Positional Syntax
The shortest form uses a positional parameter list. The compiler generates a primary constructor, init-only properties, and all equality infrastructure automatically.
Standard Record Syntax
When you need additional methods, computed properties, or validation, use the body form.
with Expressions: Non-Destructive Mutation
Because records are immutable, you can't change a property. Instead, use a with expression to create a copy with selected properties changed.
Record Inheritance
Records support inheritance. A derived record extends the base with additional properties.
Mutable Records
Records are immutable by default, but you can declare set (not init) properties when you need mutability.
record struct (C# 10+)
For small, value-semantics types that should live on the stack, use record struct. It combines struct allocation with the record convenience syntax.
Record vs Class: Quick Comparison
class | record | record struct | |
|---|---|---|---|
| Type | Reference | Reference | Value |
| Equality | Reference (by default) | Value (all properties) | Value (all properties) |
| Immutable by default | No | Yes (init props) | No (mutable by default) |
with expression | No | Yes | Yes |
ToString() | Type name only | All properties listed | All properties listed |
| Inheritance | Yes | Yes | No |
| Allocation | Heap | Heap | Stack |
| Best for | Stateful objects, services | DTOs, value objects, events | Small value types |
Real-World Example: API Response DTO
Take It Further

The most comprehensive book covering C# 12 and .NET 8 from scratch to production.
C# 12 and .NET 8: Modern Cross-Platform Development · Mark J. Price
Get it on Amazon →As an Amazon Associate I earn from qualifying purchases.
Related Articles
Use a struct for small simple value types like Point or Color. Use a class for complex types with behavior. Structs are stack-allocated value types in C#.
const fields are compile-time constants set at declaration. readonly fields are runtime constants that can be assigned in the constructor in C#.
Nullable reference types in C# 8.0+ make nullability explicit to prevent NullReferenceException. Enable with the Nullable enable setting in your project.
Learn C# pattern matching with is expressions, switch expressions, type patterns, property patterns, relational patterns, and list patterns.