RemoveRange method in ArrayList

In this article I will explain the RemoveRange method of arraylist.
  • 2257

RemoveRange method removes a range of elements from the ArrayList.

Example

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            ArrayList counting = new ArrayList();

            counting.Add("one");

            counting.Add("two");

            counting.Add("three");

            counting.Add("four");

            counting.Add("five");

            counting.Add("six");

            counting.Add("seven");

            Stack numbers = new Stack();

            numbers.Push(1);

            numbers.Push(2);

            numbers.Push(3);

            numbers.Push(4);

            Console.WriteLine("The number of elements in the arraylist are:");

            foreach (object i in counting)

            {

                Console.WriteLine(i);

            }

            counting.InsertRange(7, numbers);

            Console.WriteLine("The elemets after the insertrange operation are:");

            foreach (object i in counting)

            {

                Console.WriteLine(i);

            }

            counting.RemoveRange(6, 5);

            Console.WriteLine("After apply the RemoveAt operation the arraylist is as:");

             foreach (object i in counting)

            {

                Console.WriteLine(i);

            }       

        }

    }

}


Output

 

removerange.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

© 2019 DotNetHeaven. All rights reserved.