StringBuilder EnsureCapacity method
using System;
using System.Text;
class StringBuilderFeatures
{
static void Main(string[] args)
{
StringBuilder buffer =new StringBuilder( "Hello, how are you?" );
string output = "buffer = " + buffer.ToString() +
"\nLength = " + buffer.Length +
"\nCapacity = " + buffer.Capacity;
buffer.EnsureCapacity( 75 );
output += "\n\nNew capacity = " +buffer.Capacity;
// truncate StringBuilder by setting Length property
buffer.Length = 10;
output += "\n\nNew length = " +
buffer.Length + "\nbuffer = ";
// use StringBuilder indexer
for ( int i = 0; i < buffer.Length; i++ )
output += buffer[ i ];
Console.WriteLine( output);
}
}
Related examples in the same category