Queue<T>.CopyTo(T[], Int32) मेथड का उपयोग कतार तत्वों को 1-D ऐरे में कॉपी करने के लिए किया जाता है।
उदाहरण
आइए अब एक उदाहरण देखते हैं:
using System;
using System.Collections.Generic;
public class Demo{
public static void Main(){
Queue queue = new Queue();
queue.Enqueue("K");
queue.Enqueue("T");
String[] strArr = new String[4];
strArr[0] = "One";
strArr[1] = "Two";
strArr[2] = "Three";
strArr[3] = "Four";
Console.WriteLine("\nऐरे तत्व: ");
for (int i = 0; i < strArr.Length; i++){
Console.WriteLine(strArr[i]);
}
queue.CopyTo(strArr, 2);
Console.WriteLine("\nकॉपी करने के बाद ऐरे में है: ");
for (int i = 0; i < strArr.Length; i++){
Console.WriteLine("arr[{0}] : {1}", i, strArr[i]);
}
}
}
आउटपुट
यह निम्नलिखित आउटपुट देगा:
One Two Three Four कॉपी करने के बाद ऐरे में है: arr[0] : One arr[1] : Two arr[2] : K arr[3] : T