StringBuilder EnsureCapacity method : StringBuffer StringBuilder : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » StringBuffer StringBuilder »

 

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);
      }
   }


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» StringBuffer StringBuilder