전체 LinkedList를 Array에 복사하려면 코드는 다음과 같습니다. -
예
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
LinkedList<int> list = new LinkedList<int>();
list.AddLast(100);
list.AddLast(200);
list.AddLast(300);
int[] strArr = new int[5];
list.CopyTo(strArr, 0);
foreach(int str in strArr){
Console.WriteLine(str);
}
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
100 200 300 0 0
예
이제 다른 예를 살펴보겠습니다 -
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
LinkedList<int> list = new LinkedList<int>();
list.AddLast(100);
list.AddLast(200);
list.AddLast(300);
int[] strArr = new int[10];
list.CopyTo(strArr, 4);
foreach(int str in strArr){
Console.WriteLine(str);
}
}
} 출력
이것은 다음과 같은 출력을 생성합니다 -
0 0 0 0 100 200 300 0 0 0