Using the TrimToSize() method to reduce the capacity of ArrayList : ArrayList : Data Structure C# Examples


C# Examples » Data Structure » ArrayList »

 

Using the TrimToSize() method to reduce the capacity of ArrayList









    
using  System;
using  System.Collections;

class  MainClass
{
    public  static  void  Main()
    {
        ArrayList  myArrayList  =  new  ArrayList();
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        myArrayList.Add("A");
        

        string[]  anotherStringArray  =  {"Here's",  "some",  "more",  "text"};
        myArrayList.SetRange(0,  anotherStringArray);

        myArrayList.TrimToSize();
        Console.WriteLine("myArrayList.Capacity  =  "  +  myArrayList.Capacity);

    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» ArrayList