Records (C# 9)
Records (C# 9)
Section titled โ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.