C# এ Queue.Clear() পদ্ধতিটি সারি থেকে সমস্ত বস্তু মুছে ফেলার জন্য ব্যবহৃত হয়।
সিনট্যাক্স
সিনট্যাক্স নিম্নরূপ -
public virtual void Clear ();
উদাহরণ
আসুন এখন একটি উদাহরণ দেখি -
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..."); foreach(int i in queue) { Console.WriteLine(i); } Console.WriteLine("Count of elements in the Queue = "+queue.Count); queue.Clear(); Console.WriteLine("Count of elements in the Queue [Updated] = "+queue.Count); } }
আউটপুট
এটি নিম্নলিখিত আউটপুট তৈরি করবে -
Queue... 100 200 300 400 500 600 700 800 900 1000 Count of elements in the Queue = 10 Count of elements in the Queue [Updated] = 0
উদাহরণ
এখন আরেকটি উদাহরণ দেখা যাক -
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); Console.WriteLine("Queue..."); foreach(int i in queue) { Console.WriteLine(i); } Console.WriteLine("Count of elements in the Queue = "+queue.Count); queue.Enqueue(800); queue.Enqueue(900); queue.Enqueue(1000); Console.WriteLine("Count of elements in the Queue [Updated] = "+queue.Count); queue.Clear(); Console.WriteLine("Count of elements in the Queue [Updated] = "+queue.Count); } }
আউটপুট
এটি নিম্নলিখিত আউটপুট তৈরি করবে -
Queue... 100 200 300 Count of elements in the Queue = 3 Count of elements in the Queue [Updated] = 6 Count of elements in the Queue [Updated] = 0