with expression
C# syntax that copies a record and changes only the members you name, as in kettle with { Name = "Teapot" }.
In more detail
It also works on structs and anonymous types. The original is left untouched, which is how you "change" immutable data.
Related terms
- 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.
- immutable — Something that cannot be changed after it is created; to change it you make a new one.
Taught in
- Records, Pattern Matching, and Modern C# — Modern .NET Core, C# & Enterprise Microservices