অন্য সংগ্রহ থেকে একটি সারি তৈরি করতে, কোডটি নিম্নরূপ -
উদাহরণ
using System; using System.Collections.Generic; public class Demo { public static void Main() { Queue<string> queue = new Queue<string>(); queue.Enqueue("One"); queue.Enqueue("Two"); queue.Enqueue("Three"); Console.WriteLine("Queue elements..."); foreach(string str in queue) { Console.WriteLine(str); } Console.WriteLine("\nArray elements..."); Queue<string> arr = new Queue<string>(queue.ToArray()); foreach(string str in arr) { Console.WriteLine(str); } } }
আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেQueue elements... One Two Three Array elements... One Two Three
এখন আরেকটি উদাহরণ দেখা যাক -
উদাহরণ
using System; using System.Collections.Generic; public class Demo { public static void Main() { Queue<int> queue = new Queue<int>(); queue.Enqueue(100); queue.Enqueue(200); queue.Enqueue(300); queue.Enqueue(400); queue.Enqueue(500); queue.Enqueue(600); queue.Enqueue(700); queue.Enqueue(800); queue.Enqueue(900); queue.Enqueue(1000); Console.WriteLine("Queue elements..."); foreach(int val in queue) { Console.WriteLine(val); } Console.WriteLine("\nArray elements..."); Queue<int> arr = new Queue<int>(queue.ToArray()); foreach(int val in arr) { Console.WriteLine(val); } } }
আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেQueue elements... 100 200 300 400 500 600 700 800 900 1000 Array elements... 100 200 300 400 500 600 700 800 900 1000