mediumConceptCodingMidSenior
When would you make a type a record, a struct, or a class? What does each choose for you?
4 min readUpdated 2026-08-15
Answer
Short answer
A class gives reference identity, a struct gives value semantics and lives inline, and a record is a class with value-based equality and a copy-with-changes syntax generated for you.
Was this answer helpful?
Likely follow-ups
- What does `with` copy, and what does it leave shared?
- Why is a large mutable struct in a list a performance problem?
- Two records hold the same array. Are they equal?
- When would you write `readonly record struct`, and what does each word buy?
Related questions
- What is the difference between a value type and a reference type in C#, and what do nullable reference types guarantee?mediumAlso on value-types and structs5 min
- A client disconnects but your server keeps working on their request. How does cancellation actually propagate in .NET?mediumAlso on csharp4 min
- You build a LINQ query, then change the list it came from, then enumerate it. What do you get?mediumAlso on csharp5 min
- How do records, sealed types and pattern matching change the way you model a domain?mediumAlso on records5 min