ArrayList의 요소 범위에 걸쳐 컬렉션의 요소를 복사하려면 코드는 다음과 같습니다. -
예시
using System;
using System.Collections;
public class Demo {
public static void Main(){
ArrayList arrList = new ArrayList();
arrList.Add("A");
arrList.Add("B");
arrList.Add("C");
arrList.Add("D");
Console.WriteLine("ArrayList elements...");
for (int i = 0; i < arrList.Count; i++) {
Console.WriteLine("" + arrList[i]);
}
string[] str = { "Demo", "Text" };
arrList.SetRange(0, str);
Console.WriteLine("After copying...");
for (int i = 0; i < arrList.Count; i++) {
Console.WriteLine("" + arrList[i]);
}
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
ArrayList elements... A B C D After copying... Demo Text C D
예시
이제 다른 예를 살펴보겠습니다 -
using System;
using System.Collections;
public class Demo {
public static void Main(){
ArrayList arrList = new ArrayList();
arrList.Add("One");
arrList.Add("Two");
arrList.Add("Three");
arrList.Add("Four");
arrList.Add("Five");
arrList.Add("Six");
arrList.Add("Seven");
arrList.Add("Eight");
Console.WriteLine("ArrayList elements...");
for (int i = 0; i < arrList.Count; i++) {
Console.WriteLine("" + arrList[i]);
}
string[] str = { "Demo", "Text" };
arrList.SetRange(2, str);
Console.WriteLine("After copying...");
for (int i = 0; i < arrList.Count; i++) {
Console.WriteLine("" + arrList[i]);
}
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
ArrayList elements... One Two Three Four Five Six Seven Eight After copying... One Two Demo Text Five Six Seven Eight