Gets or sets the maximum number of characters that can be contained
using System;
using System.Text;
class Sample
{
public static void Main()
{
StringBuilder sb1 = new StringBuilder("abc");
StringBuilder sb2 = new StringBuilder("abc", 16);
Console.WriteLine("a1) sb1.Length = {0}, sb1.Capacity = {1}", sb1.Length, sb1.Capacity);
Console.WriteLine("a2) sb2.Length = {0}, sb2.Capacity = {1}", sb2.Length, sb2.Capacity);
Console.WriteLine("a3) sb1.ToString() = \"{0}\", sb2.ToString() = \"{1}\"", sb1.ToString(),sb2.ToString());
Console.WriteLine("a4) sb1 equals sb2: {0}", sb1.Equals(sb2));
Console.WriteLine("Ensure sb1 has a capacity of at least 50 characters.");
sb1.EnsureCapacity(50);
Console.WriteLine("b1) sb1.Length = {0}, sb1.Capacity = {1}", sb1.Length, sb1.Capacity);
Console.WriteLine("b2) sb2.Length = {0}, sb2.Capacity = {1}", sb2.Length, sb2.Capacity);
Console.WriteLine("b3) sb1.ToString() = \"{0}\", sb2.ToString() = \"{1}\"", sb1.ToString(),sb2.ToString());
Console.WriteLine("b4) sb1 equals sb2: {0}", sb1.Equals(sb2));
}
}
Related examples in the same category