StringBuilder internally maintains an array of characters that it manages dynamically.
The workhorse methods of StringBuilder are Append(), Insert(), and AppendFormat().
These methods are richly overloaded in order to support appending and inserting string
forms of the many common types. When you create a StringBuilder instance, you have
various constructors to choose from. The default constructor creates a new StringBuilder
instance with the system-defined default capacity. However, that capacity doesn??™t constrain
the size of the string that it can create. Rather, it represents the amount of string data the
StringBuilder can hold before it needs to grow the internal buffer and increase the capacity.
If you know how big your string will likely end up being, you can give the StringBuilder that
number in one of the constructor overloads, and it will initialize the buffer accordingly. This
can help the StringBuilder instance from having to reallocate the buffer too often while you
fill it.
You can also define the maximum-capacity property in the constructor overloads. By
default, the maximum capacity is System.Int32.MaxValue, which is currently 2,147,483,647,
but that exact value is subject to change as the system evolves. If you need to protect your
StringBuilder buffer from growing over a certain size, you may provide an alternate maximum
capacity in one of the constructor overloads.
Pages:
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311