C#-এ Queue.Dequeue() পদ্ধতিটি সারির শুরুতে বস্তুটিকে সরাতে এবং ফিরিয়ে দিতে ব্যবহৃত হয়।
সিনট্যাক্স
সিনট্যাক্স নিম্নরূপ -
public virtual object Dequeue ();
উদাহরণ
আসুন এখন একটি উদাহরণ দেখি -
using System; using System.Collections.Generic; public class Demo { public static void Main() { Queue<string> queue = new Queue<string>(); queue.Enqueue("A"); queue.Enqueue("B"); queue.Enqueue("C"); queue.Enqueue("D"); queue.Enqueue("E"); queue.Enqueue("F"); queue.Enqueue("G"); Console.WriteLine("Count of elements = "+queue.Count); Console.WriteLine("Element at the beginning of queue = " + queue.Peek()); queue.Dequeue(); queue.Dequeue(); queue.Dequeue(); Console.WriteLine("Count of elements = "+queue.Count); } }
আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেCount of elements = 7 Element at the beginning of queue = A Count of elements = 4
উদাহরণ
এখন আরেকটি উদাহরণ দেখা যাক -
using System; using System.Collections.Generic; public class Demo { public static void Main() { Queue<string> queue = new Queue<string>(); queue.Enqueue("Gary"); queue.Enqueue("Jack"); queue.Enqueue("Ryan"); queue.Enqueue("Kevin"); queue.Enqueue("Mark"); queue.Enqueue("Jack"); queue.Enqueue("Ryan"); queue.Enqueue("Kevin"); Console.Write("Count of elements = "); Console.WriteLine(queue.Count); Console.WriteLine("Queue..."); foreach(string i in queue) { Console.WriteLine(i); } queue.Dequeue(); queue.Dequeue(); Console.WriteLine("Queue...UPDATED"); foreach(string i in queue) { Console.WriteLine(i); } Console.Write("Count of elements (updated) = "+queue.Count); queue.Clear(); Console.Write("\nCount of elements (updated AGAIN) = "); Console.WriteLine(queue.Count); } }
আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেCount of elements = 8 Queue... Gary Jack Ryan Kevin Mark Jack Ryan Kevin Queue...UPDATED Ryan Kevin Mark Jack Ryan Kevin Count of elements (updated) = 6 Count of elements (updated AGAIN) = 0