Computer >> कंप्यूटर >  >> प्रोग्रामिंग >> C#

जांचें कि कोई तत्व सी # में कतार में है या नहीं

यह जांचने के लिए कि कोई तत्व कतार में है या नहीं, कोड इस प्रकार है -

उदाहरण

using System;
using System.Collections.Generic;
public class Demo {
   public static void Main(){
      Queue<string> queue = new Queue<string>();
      queue.Enqueue("Electronics");
      queue.Enqueue("Accessories");
      queue.Enqueue("Toys");
      queue.Enqueue("Books");
      queue.Enqueue("Furniture");
      queue.Enqueue("Clothing");
      queue.Enqueue("Footwear");
      queue.Enqueue("Cookware");
      queue.Enqueue("Pet Supplies");
      Console.WriteLine("Elements in the Queue...");
      foreach(var element in queue){
         Console.WriteLine(element);
      }
      Console.WriteLine("Do the queue has the element Books? = "+queue.Contains("Books"));
   }
}

आउटपुट

यह निम्नलिखित आउटपुट देगा -

Elements in the Queue...
Electronics
Accessories
Toys
Books
Furniture
Clothing
Footwear
Cookware
Pet Supplies
Do the queue has the element Books? = True

उदाहरण

आइए एक और उदाहरण देखें -

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(1000);
      Console.WriteLine("Elements in the Queue...");
      foreach(var element in queue){
         Console.WriteLine(element);
      }
      Console.WriteLine("Do the queue has the element 50? = "+queue.Contains(50));
   }
}

आउटपुट

यह निम्नलिखित आउटपुट देगा -

Elements in the Queue...
100
200
300
400
500
600
700
800
1000
Do the queue has the element 50? = False

  1. सी # में कतार वर्ग क्या है?

    C# में ऑब्जेक्ट्स के फर्स्ट-इन फर्स्ट-आउट संग्रह का प्रतिनिधित्व करने के लिए, Queue क्लास का उपयोग करें। जब आप सूची में कोई आइटम जोड़ते हैं, तो उसे एनक्यू कहा जाता है, और जब आप किसी आइटम को हटाते हैं, तो उसे डेक कहा जाता है। कतार वर्ग के कुछ तरीकों में शामिल हैं। Sr.No विधि और विवरण 1 सार्वजनिक आ

  1. सी # में कतार इंटरफ़ेस

    Queue ऑब्जेक्ट के फर्स्ट-इन, फर्स्ट-आउट संग्रह का प्रतिनिधित्व करता है। इसका उपयोग तब किया जाता है जब आपको आइटम्स के लिए फर्स्ट-इन, फर्स्ट-आउट एक्सेस की आवश्यकता होती है। जब आप सूची में कोई आइटम जोड़ते हैं, तो उसे एनक्यू कहा जाता है, और जब आप किसी आइटम को हटाते हैं, तो उसे डेक कहा जाता है। आइए कतार

  1. सी # में कतार वर्ग की गणना संपत्ति क्या है?

    कतार वर्ग के तत्वों की संख्या ज्ञात करने के लिए गणना गुण का उपयोग करें। निम्नलिखित घोषणा जैसे तत्वों को सेट करें - Queue q = new Queue(); q.Enqueue(1); q.Enqueue(2); q.Enqueue(3); q.Enqueue(4); फिर तत्वों को गिनने के लिए काउंट प्रॉपर्टी का उपयोग करें - q.Count क्यू क्लास में काउंट प्रॉपर्टी के सा