Advertisement
Advanced C#, Value vs Reference Types

Why can mutable structs cause subtle bugs?

Short answer

Because structs copy on assignment and when stored in some collections/properties, mutating a copy does not change the original — leading to lost updates. Prefer readonly structs.

Save C# mock interview
Advertisement
AModel answer
Because structs copy on assignment and when stored in some collections/properties, mutating a copy does not change the original — leading to lost updates. Prefer readonly structs.
struct P { public int X; }
var list = new List<P>{ new P() };
list[0].X = 5; // compile error / would mutate a copy
Real-world example
A mutable struct field on a class property silently discards writes.