What is a record type in C#?
Answer
Records (C# 9+) are a special class type designed for immutable data models with value-based equality. By default, records are reference types (record class) where two records with the same property values are considered equal (unlike regular classes). record struct (C# 10+) is a value-type record. Declaration: public record Person(string FirstName, string LastName, int Age);. Features: (1) Value equality: new Person("Alice", "Smith", 30) == new Person("Alice", "Smith", 30) → true. (2) with expressions: var updated = alice with { Age = 31 }; — creates a copy with specified properties changed. (3) Deconstruction: var (first, last, age) = alice;. (4) Auto-generated ToString() showing all properties. (5) Immutability: positional properties are init-only by default. Use records for DTOs, value objects, and any immutable data transfer scenarios.