question about strings & stringbuilder!
this is the code
people say me use stringbuilder instead of appending to a string they say the way I did can be slower and resource consuming he don't reply further thought he is busy man can any gentleman teach me why is it he just said strings are immutable which is also what I don't think cuz I can add new value to strings I can assign new value to strings why they say they are immutable! help me this is confusing for me!
4 Replies
immutable means
"a" + "b"
will create a new string "ab" and the previous 2 wont change
you cant change strings, only create a new one
Appending to string stores every iteration in memory
Stringbuilder stores the individual elements, and only glues them together when requested
It's not that different from doing
But stringbuilder has plenty of additional functionality
thanks for this information! zzzzzzzzzzzzzzzz and eeeeeeeeeeeeeeeee
C# is cool
lmao