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

C# में StringDictionary में किसी विशिष्ट मान की जांच कैसे करें

C# में StringDictionary किसी विशिष्ट मान को रखता है या नहीं, यह जांचने के लिए ContainsValue() मेथड का उपयोग किया जाता है। यह मेथड एक बूलियन मान लौटाता है: true यदि मान मौजूद है, अन्यथा false।

उदाहरण 1

using System;
using System.Collections;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        StringDictionary strDict1 = new StringDictionary();
        strDict1.Add("A", "John");
        strDict1.Add("B", "Andy");
        strDict1.Add("C", "Tim");
        strDict1.Add("D", "Ryan");
        strDict1.Add("E", "Kevin");
        strDict1.Add("F", "Katie");
        strDict1.Add("G", "Brad");

        Console.WriteLine("StringDictionary1 तत्व...");
        foreach (DictionaryEntry d in strDict1) {
            Console.WriteLine(d.Key + " " + d.Value);
        }
        Console.WriteLine("क्या StringDictionary1 में कुंजी G है? " + strDict1.ContainsKey("G"));
        Console.WriteLine("क्या StringDictionary1 में मान Ryan है? " + strDict1.ContainsValue("Ryan"));

        StringDictionary strDict2 = new StringDictionary();
        strDict2.Add("A", "John");
        strDict2.Add("B", "Andy");
        strDict2.Add("C", "Tim");
        strDict2.Add("D", "Ryan");
        strDict2.Add("E", "Kevin");
        strDict2.Add("F", "Katie");
        strDict2.Add("G", "Brad");

        Console.WriteLine("\nStringDictionary2 तत्व...");
        foreach (DictionaryEntry d in strDict2) {
            Console.WriteLine(d.Key + " " + d.Value);
        }
        Console.WriteLine("\nक्या Dictionary2, Dictionary1 के बराबर है? = " + strDict2.Equals(strDict1));
        Console.WriteLine("क्या StringDictionary2 में कुंजी B है? " + strDict2.ContainsKey("B"));
    }
}

आउटपुट

StringDictionary1 तत्व...
a John
b Andy
c Tim
d Ryan
e Kevin
f Katie
g Brad
क्या StringDictionary1 में कुंजी G है? True
क्या StringDictionary1 में मान Ryan है? True

StringDictionary2 तत्व...
a John
b Andy
c Tim
d Ryan
e Kevin
f Katie
g Brad
क्या Dictionary2, Dictionary1 के बराबर है? = False
क्या StringDictionary2 में कुंजी B है? True

उदाहरण 2

using System;
using System.Collections;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        StringDictionary strDict1 = new StringDictionary();
        strDict1.Add("U", "Electronics");
        strDict1.Add("V", "Toys");
        strDict1.Add("W", "Books");
        strDict1.Add("X", "Accessories");

        Console.WriteLine("StringDictionary1 तत्व...");
        foreach (DictionaryEntry d in strDict1) {
            Console.WriteLine(d.Key + " " + d.Value);
        }
        Console.WriteLine("क्या StringDictionary1 में कुंजी G है? " + strDict1.ContainsKey("G"));
        Console.WriteLine("क्या StringDictionary1 में मान Footwear है? " + strDict1.ContainsValue("Footwear"));

        StringDictionary strDict2 = new StringDictionary();
        strDict2.Add("A", "John");
        strDict2.Add("B", "Andy");
        strDict2.Add("C", "Tim");
        strDict2.Add("D", "Ryan");
        strDict2.Add("E", "Kevin");
        strDict2.Add("F", "Katie");
        strDict2.Add("G", "Brad");

        Console.WriteLine("\nStringDictionary2 तत्व...");
        foreach (DictionaryEntry d in strDict2) {
            Console.WriteLine(d.Key + " " + d.Value);
        }
        Console.WriteLine("\nक्या Dictionary2, Dictionary1 के बराबर है? = " + strDict2.Equals(strDict1));
        Console.WriteLine("क्या StringDictionary2 में कुंजी B है? " + strDict2.ContainsKey("B"));
    }
}

आउटपुट

StringDictionary1 तत्व...
x Accessories
u Electronics
v Toys
w Books
क्या StringDictionary1 में कुंजी G है? False
क्या StringDictionary1 में मान Footwear है? False

StringDictionary2 तत्व...
a John
b Andy
c Tim
d Ryan
e Kevin
f Katie
g Brad
क्या Dictionary2, Dictionary1 के बराबर है? = False
क्या StringDictionary2 में कुंजी B है? True
  1. - C# में Collection में किसी तत्व की जांच कैसे करें

    C# में Collection<T> किसी विशिष्ट तत्व को रखता है या नहीं, यह जांचने के लिए Contains() मेथड का उपयोग किया जाता है। यह मेथड एक बूलियन मान लौटाता है। उदाहरण 1 using System; using System.Collections.ObjectModel; public class Demo { public static void Main() { Collection col = new Col

  1. - C# में HashSet में निर्दिष्ट तत्व है या नहीं जांचें

    C# में HashSet किसी विशिष्ट तत्व को रखता है या नहीं, यह जांचने के लिए Contains() मेथड का उपयोग किया जाता है। यह मेथड एक बूलियन मान लौटाता है। उदाहरण 1 using System; using System.Collections.Generic; public class Demo { public static void Main() { HashSet set1 = new HashSet(); se

  1. - जावा प्रोग्राम: ऐरे में मान मौजूद है या नहीं चेक करना

    इस लेख में हम समझेंगे कि ऐरे में दिया गया मान मौजूद है या नहीं, यह कैसे चेक किया जाता है। यह ऐरे एलिमेंट्स पर इटरेट करके और दिए गए इनपुट की तुलना ऐरे एलिमेंट्स से करके किया जाता है। डेमोनस्ट्रेशन इनपुट: खोजने वाली संख्या दर्ज करें: 25 इंटीजर ऐरे के एलिमेंट्स: 15 20 25 30 35 आउटपुट: ऐरे में दिया ग