Khalid Abuhakmeh 7/18/2023

C# Records, the With Keyword, and Reference Types

Read Original

This technical article discusses a subtle bug that can occur in C# when using the 'with' keyword to copy records that contain reference type members. It explains how the copy is shallow, leading to shared mutable state, and demonstrates solutions like explicit property setting and copy constructors to ensure proper immutability.

C# Records, the With Keyword, and Reference Types

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser