A String object is called immutable (read-only), and because its value cannot was modified after it had been created. Methods that appear to modify a string object actually return a new string object that contains the Modi Fication.
Because strings is immutable, string manipulation routines that perform repeated additions or deletions to what appears t O is a single string can exact a significant performance penalty.
< Span style= "line-height:18px" >you can use the stringbuilder class instead of the string class for operations That does multiple changes to the value of a string. Unlike instances of the string class, stringbuilder objects is mutable; When you concatenate, append, or delete substrings from a string, the operations is performed on a single string.
A&NBSP; stringbuilder object maintains a buffer to accommodate expansions to the string. New data is appended to the buffer if hostel is available; Otherwise, a new, larger buffer is allocated, data from the original buffer was copied to the new buffer, and the new data is then appended to the new buffer.
although The stringbuilder class generally offers better performance than The string class, should not automatically replace string with stringbuilder whenever You want to manipulate strings. Performance depends on the size of the string, the amount of the memory to is allocated for the new string, the system on whic H your app is executing, and the type of operation. You should is prepared to test your app to determine Whether stringbuilder Actually offers a significant performance improvement.
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
C #-String and StringBuilder