संपूर्ण 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