C# › Records & Pattern Matching

What does the with expression do?

Beginner

Answer

with creates a copy of a record with some properties changed, leaving the original unchanged (non-destructive mutation).
var updated = order with { Status = "Shipped" };
Real-world example Producing a new immutable state object from the previous one in a reducer/state store.