3 ms·
In most cases you WOULD know that StringBuilder is just fine and no thread contention exists. Most common uses of StringBuilder are where the StringBuilder is
by DannyB2 10y ago
In most cases you WOULD know that StringBuilder is just fine and no thread contention exists. Most common uses of StringBuilder are where the StringBuilder is a local variable used within a single function to build up a string, and then to give you the actual string that was built up. After that the StringBuilder goes out of scope and the garbage collector will eat it up when it gets hungry. The string that StringBuilder gave you is immutable, therefore no other thread can change its value. (And hence the reason why StringBuilder is useful -- it is like a mutable string.)