4
Answers

Immutability drawbacks

Ask a question
Alexandre

Alexandre

14y
3.7k
1
Hi all,

I'm currently working on a school project in c# and I've just got aware of the immutability concepts and advantages in c#.

The question is: what are the drawbacks of using it? I mean... every time you modify a string you create a new one, so if you have many strings to modify, there is lots of creation/deletion.. At which point the disadvantages surpass the advantages? Or, put in other words, when should I create immutable types and when should I not?

Thanks :)

PS: My example uses strings, but that's not about that type I'm worried (use stringbuilder if there's lots of manipulation to do), it's about another type I've created and that requires many manipulations over a lifetime.

Answers (4)