Mega Code Archive

 
Categories / C# by API / System Collections
 

ArrayList TrimToSize()

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