The with keyword in C# facilitates clean and safe code by allowing you to clone an existing object and modify certain properties without affecting the original. This feature is particularly useful for immutable types, ensuring that objects remain unchanged once created. Starting with C# 10, the with keyword is applicable to structs as well, leveraging autogenerated clone methods for record types.

1m watch time

Sort: