When I did some F# programming back in the day I really like the with keyword that allowed to create a copy of an object with one or more updated fields.
Thanks to that you didn't have to manually copy over the ones that didn't change. F# had immutability baked in for a long time so it's not a surprise that such concepts existed.
When immutability came to C#, it also had to adopt similar patterns to avoid over re-assigning unchanged properties.
Just recently I reminded myself that there is this option, that with record types, we can construct a new one with some properties updated.
Underneath, a Clone method is called with setting the property but this is more concise, and I think more readable.
Docs ๐: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/with-expression
#dotnet #records #with #immutability
---
If you find this useful, consider giving a like & share โค.