Why are mutable structs “evil”?

Dirk Vollmar picture Dirk Vollmar · Jan 14, 2009 · Viewed 81.2k times · Source

Following the discussions here on SO I already read several times the remark that mutable structs are “evil” (like in the answer to this question).

What's the actual problem with mutability and structs in C#?

Answer

trampster picture trampster · Jan 14, 2009

Structs are value types which means they are copied when they are passed around.

So if you change a copy you are changing only that copy, not the original and not any other copies which might be around.

If your struct is immutable then all automatic copies resulting from being passed by value will be the same.

If you want to change it you have to consciously do it by creating a new instance of the struct with the modified data. (not a copy)