C#workingdotnet

Records and pattern matching

Immutable value types that compare by content, plus the patterns that read them apart.

record gives you value equality, with-expressions, and deconstruction for free — then property and positional patterns let switch branch on shape.

Records compare by value

C#intro
0ms
TrueTrueFalseFalseTruePoint { X = 2, Y = 3 }
Reference · output compiled offline, not runnable in-browser

a == b and a.Equals(b) are both True because records compare by content, yet ReferenceEquals(a, b) is False — they are equal-by-value but distinct objects. Matching values also yield equal hash codes, and the synthesised ToString prints Point { X = 2, Y = 3 }.