Skip to content

Records (C# 9)

public record Person(string Name, int Age);
var p1 = new Person("Ada", 36);
var p2 = p1 with { Age = 37 };
Console.WriteLine(p1 == p2); // false (value-based)

Notes

  • Records compare by value; classes compare by reference.
  • Use with-expressions to copy with modifications.