Clear method in ArrayList

In this article I will explain the clear method of arraylist.
  • 2130

Clear method removes all elements from the ArrayList, when we apply the clear method the number of elements becomes zero as it remove all the elements from the arraylist.

Example

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            ArrayList months = new ArrayList();

            months.Add("march");

            months.Add("april");

            months.Add("may");

            months.Add("june");

            months.Add("july");

            //before apply the clear method

            Console.WriteLine("The elements in the arraylist are:" + months.Count);

            months.Clear();

            Console.WriteLine("After apply the clear method the arraylist is:" + months.Count);

        }

    }

}


Output

 

clear.jpg 

 

Further Readings
 
You may also want to read these related articles.

Ask Your Question

Got a programming related question? You may want to post your question here
 

 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.