SetRange method in ArrayList

In this article I will explain the SetRange method of ArrayList.
  • 2450

Introduction

The SetRange method of ArrayList copies the elements of a collection over a range of elements in the ArrayList,that means we define an arraylist and a collection then the setrange method copies the collection into the arraylist from the index position of the arraylist that we mention in the setrange's first argument.

Example

namespace ConsoleApplication6

{

    class Program

    {

        static void Main(string[] args)

        {

            //create the arraylist named days

            ArrayList days = new ArrayList();

            //add the elements in the arraylist

            days.Add("Sunday");

            days.Add("Monday");

            days.Add("Tuesday");

            days.Add("Wednesday");

            days.Add("Thusday");

            days.Add("Friday");

            days.Add("Saturday");

            Console.WriteLine("The arraylist is as:");

            foreach (string str in days)

            {

                Console.WriteLine(str);

            }

            Console.WriteLine();

            Stack years = new Stack();

            years.Push("January");

            years.Push("Febuary");

            years.Push("March");

            years.Push("April");

            years.Push("May");

            Console.WriteLine("The stack is as:");

            foreach (string a in years)

            {

                Console.WriteLine(a);

            }

            Console.WriteLine();

            days.SetRange(1, years);

            Console.WriteLine("After apply the SetRange method the arraylist is as:");

            foreach (string s in days)

            {

                Console.WriteLine(s);

            }

        }

    }

}

 

Output

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