using System.Collections; // Creating an ArrayList instance ArrayList myArrayList = new ArrayList(); // Adding elements to the ArrayList myArrayList.Add("element 1"); myArrayList.Add("element 2"); myArrayList.Add("element 3"); // Clearing the ArrayList myArrayList.Clear(); // The ArrayList is now empty
using System.Collections; public void ClearArrayList(ArrayList list) { list.Clear(); } // Creating and Populating an ArrayList ArrayList myArrayList = new ArrayList(); myArrayList.Add("element 1"); myArrayList.Add("element 2"); myArrayList.Add("element 3"); // Clearing the ArrayList using a function ClearArrayList(myArrayList); // The ArrayList is now emptyThis method is available in the System.Collections namespace which is a part of the .NET Framework Class Library.