Skip to content

C# Feature - with expressions

With expressions provide non-destructive mutation by copying an existing record or struct and applying targeted changes.

C# 9.0 (2020)

var updated = new Person(existing.Name, 37);
var updated = existing with { Age = 37 };
  • With expressions shine most with immutable data models.
  • Use them with records or value objects that should not be mutated in place.