Copy a collection to a range of elements in the ArrayList in CSharp
Description
The following code shows how to copy a collection to a range of elements in the ArrayList.
Example
using System;/*w ww.j a va 2 s . co m*/
using System.Collections;
class MainClass
{
public static void Main()
{
ArrayList myArrayList = new ArrayList();
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
myArrayList.Add("A");
for (int i = 0; i < myArrayList.Count; i++){
Console.WriteLine(myArrayList[i]);
}
string[] anotherStringArray = {"Here's", "some", "more", "text"};
myArrayList.SetRange(0, anotherStringArray);
for (int i = 0; i < myArrayList.Count; i++){
Console.WriteLine(myArrayList[i]);
}
}
}
The code above generates the following result.