The new C# 9.0 syntax allows for a new kind of expression:
var newPerson = oldPerson with { Age = "21" };
Following questions arise when looking at the previous code line:
- Is it a reference or a new object copy?
- If it's a reference, what about the inheritance? Consider the following code line:
Person child = new Child{ FirstName = "Jan", LastName = "Brown", IsInKindergarten = false };
Person person = child with { LastName = "Williams" }
Does the compiler allow the person object to inherit the IsInKindergarten property?