record
A C# type declared with the record keyword for data, for which the compiler generates a constructor, properties, value equality, a readable ToString and with-expression copying.
In more detail
record Product(int Id, string Name); is one line. Records suit request and response types, whose data does not change in place. They are reference types unless declared record struct.
Example
public record Product(int Id, string Name);Related terms
- value equality — Treating two objects as equal when their members hold equal values, even if they are separate objects.
- with expression — C# syntax that copies a record and changes only the members you name, as in kettle with { Name = "Teapot" }.
- record struct — A record declared as a value type, with the same generated members but copied by value and not allocated on the heap.
- DTO — A plain object whose only job is to carry data across a boundary, such as the body of an API request or response.
- class — A blueprint in code that bundles data and the functions that work on it, from which objects are made.
Taught in
- The C# Language: Types, Variables, and Flow Control — Modern .NET Core, C# & Enterprise Microservices
- Collections, Generics, and LINQ — Modern .NET Core, C# & Enterprise Microservices
- Records, Pattern Matching, and Modern C# — Modern .NET Core, C# & Enterprise Microservices
- Manual Object Mapping — Modern .NET Core, C# & Enterprise Microservices
- Model Validation and FluentValidation — Modern .NET Core, C# & Enterprise Microservices