C# records: value equality, with-expressions, positional syntax
Short answer
A record is a reference type built for data. Two records of the same type with the same values compare equal. Use with for a copy that changes selected properties. [S1]
Sketch
public record Person(string First, string Last);
var p2 = p1 with { Last = "Smith" };
Points
- Records compare by value, not by reference identity. [S1]
withgives nondestructive updates. [S1]- Positional records and record structs are everyday features of the type. [S2]
- Entity Framework Core still expects reference equality for tracked entities. [S1]
Claims
- id: C1 claim: Records of the same type with the same values are equal. source: S1 evidence: "equal if they are of the same type and store the same values"
- id: C2 claim: with expressions support nondestructive mutation. source: S1 evidence: "use a with expression to achieve nondestructive mutation"
- id: C3 claim: EF Core depends on reference equality. source: S1 evidence: "Entity Framework Core depends on reference equality"
- id: C4 claim: Everyday record features include value equality and with expressions. source: S2 evidence: "value equality, positional syntax, and with expressions"
Sources
- [S1] Records (C# reference). Microsoft Learn. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/record . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-05.
- [S2] Create record types in C#. Microsoft Learn. https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/records . License: CC BY 4.0 (dotnet/docs). Accessed 2026-11-05.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
Source notice: .NET documentation © Microsoft. Licensed under Creative Commons Attribution 4.0 International (https://github.com/dotnet/docs/blob/main/LICENSE).
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Microsoft Learn, Records (C# reference), CC BY 4.0 (dotnet/docs); Microsoft Learn, Create record types in C#, CC BY 4.0 (dotnet/docs).
Cite this
iinventedlight. 2026. "C# records: value equality, with-expressions, positional syntax." iinventedlight Library, iil:note:00qak38e, version of 2026-11-04. https://iinventedlight.com/library/notes/csharp-records/. License: CC-BY-4.0.
@misc{iil_note_00qak38e,
author = {{iinventedlight}},
title = {{C\# records: value equality, with-expressions, positional syntax}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/csharp-records/},
note = {Permanent ID iil:note:00qak38e. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/csharp-records.md.