GetRange method in ArrayList

In this article I will explain the GetRange method of ArrayList.
  • 3773

Introduction

GetRange method returns an ArrayList which represents a subset of the elements in the source ArrayList,or we can say that if their are twenty elements in the arraylist and we want only some elements from this then we use GetRange method to get the range of element from the specified arraylist.

Example

namespace ConsoleApplication2

{

    class Program

    {

        static void Main(string[] args)

        {

            //create the arraylist

            ArrayList arraylist1 = new ArrayList();

            arraylist1.Add(5);

            arraylist1.Add(7);

            arraylist1.Add(10);

            arraylist1.Add(15);

            arraylist1.Add(23);           

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

            foreach (int i in arraylist1)

            {

                Console.WriteLine(i);

            }

            ArrayList getrange = arraylist1.GetRange(2, 3);

            Console.WriteLine("The elements in the getrange are:");

            foreach (int i in getrange)

            {

                Console.WriteLine(i);

            }           

        }

    }

}

 

Output

 

GetRange.jpg 

Ask Your Question

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

 

 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.