Record Types in C#

From the C# Programming Language cheat sheet · Records and Value Types · verified Jul 2026

Record Types

Immutable reference types with value semantics

csharp
// Record declaration
public record Person(string Name, int Age);

// Using records
var person = new Person("Alice", 30);
var older = person with { Age = 31 };

// Struct
public struct Point
{
    public double X { get; init; }
    public double Y { get; init; }
}

// Value equality
var p1 = new Person("Bob", 25);
var p2 = new Person("Bob", 25);
bool equal = p1 == p2; // true
💡 Records provide value equality and immutability by default
⚡ with expressions create copies with modified properties
📌 Records automatically implement ToString, Equals, GetHashCode
🟢 Use readonly structs for better performance
Back to the full C# Programming Language cheat sheet