InsertRange method in ArrayList
In this article I will explain the InsertRange method of arraylist.
InsertRange method Inserts the elements of a collection into the ArrayList at the specified index.
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);
}
}
}
}
|
Output
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