AddRange method in ArrayList
In this article I will explain the AddRange method of ArrayList.
Introduction
AddRange method adds the elements of an ICollection to the end of the ArrayList.There are different ways to add one ArrayList to another, but the best way is using AddRange. Internally, AddRange uses the Array.Copy or CopyTo methods, which have better performance than some loops.
Example
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
//create the first arraylist
ArrayList arraylist1 = new ArrayList();
arraylist1.Add(5);
arraylist1.Add(7);
//create the second arraylist
ArrayList arraylist2 = new ArrayList();
arraylist2.Add("Five");
arraylist2.Add("Seven");
//perform AddRange method
arraylist1.AddRange(arraylist2);
// Display the values.
foreach (object i in arraylist1)
{
Console.WriteLine(i);
}
}
}
}
|
Output

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