क्यू की शुरुआत में ऑब्जेक्ट प्राप्त करने के लिए, कोड इस प्रकार है -
उदाहरण
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()); } }
आउटपुट
यह निम्नलिखित आउटपुट देगा -
Count of elements = 7 Element at the beginning of queue = A
उदाहरण
आइए एक और उदाहरण देखें -
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.Enqueue("H"); queue.Enqueue("I"); queue.Enqueue("J"); Console.WriteLine("Count of elements = "+queue.Count); Console.WriteLine("Element at the beginning of queue = " + queue.Peek()); } }
आउटपुट
यह निम्नलिखित आउटपुट देगा -
Count of elements = 7 Element at the beginning of queue = A Count of elements = 10 Element at the beginning of queue = A