A record is still a reference type (unless you write record struct), but the compiler gives it extra behaviour:
Value equality: two records with the same property values are equal. Two class instances are equal only if they are the same object, unless you write Equals yourself.
Readable ToString that prints the property values, useful when debugging.
Non-destructive copy with the with keyword: var b = a with { Name = "New" };
A short positional syntax: public record Person(string Name, int Age);
Use records for data that is mostly about values: DTOs, API responses, messages, value objects. Use a normal class for things with identity and behaviour that changes over time, such as an EF Core entity with navigation properties and tracked changes.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
A record is still a reference type (unless you write
record struct), but the compiler gives it extra behaviour:withkeyword:var b = a with { Name = "New" };public record Person(string Name, int Age);Use records for data that is mostly about values: DTOs, API responses, messages, value objects. Use a normal class for things with identity and behaviour that changes over time, such as an EF Core entity with navigation properties and tracked changes.