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

C# में Dictionary.ContainsValue() मेथड


C# में Dictionary.ContainsValue() मेथड का उपयोग यह जांचने के लिए किया जाता है कि Dictionary<TKey,TValue> में कोई विशिष्ट मान है या नहीं।

सिंटैक्स

public bool ContainsValue (TValue val);

ऊपर, val खोजा जाने वाला मान है।

आइए अब Dictionary.ContainsValue() मेथड को लागू करने का एक उदाहरण देखें -

उदाहरण

using System; 
using System.Collections.Generic; 
public class Demo { 
    public static void Main(){ 
        Dictionary<string, string> dict = new Dictionary<string, string>(); 
        dict.Add("One", "John"); 
        dict.Add("Two", "Tom"); 
        dict.Add("Three", "Jacob"); 
        dict.Add("Four", "Kevin"); 
        dict.Add("Five", "Nathan"); 
        Console.WriteLine("तत्वों की संख्या = "+dict.Count); 
        Console.WriteLine("\nकुंजी/मान जोड़े..."); 
        foreach(KeyValuePair<string, string> res in dict){ 
            Console.WriteLine("कुंजी = {0}, मान = {1}", res.Key, res.Value); 
        } 
        if (dict.ContainsValue("Kevin")) 
            Console.WriteLine("मान मिला!"); 
        else 
            Console.WriteLine("मान डिक्शनरी में नहीं है!"); 
        dict.Clear(); 
        Console.WriteLine("साफ़ किए गए कुंजी/मान जोड़े..."); 
        foreach(KeyValuePair<string, string> res in dict){ 
            Console.WriteLine("कुंजी = {0}, मान = {1}", res.Key, res.Value); 
        } 
        Console.WriteLine("अब तत्वों की संख्या = "+dict.Count); 
    } 
}

आउटपुट

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

तत्वों की संख्या = 5 
कुंजी/मान जोड़े... 
कुंजी = One, मान = John 
कुंजी = Two, मान = Tom 
कुंजी = Three, मान = Jacob 
कुंजी = Four, मान = Kevin 
कुंजी = Five, मान = Nathan 
मान मिला! 
साफ़ किए गए कुंजी/मान जोड़े... 
अब तत्वों की संख्या = 0

आइए अब Dictionary.ContainsValue() मेथड को लागू करने का एक और उदाहरण देखें -

उदाहरण

using System; 
using System.Collections.Generic; 
public class Demo { 
    public static void Main(){ 
        Dictionary<string, string> dict = new Dictionary<string, string>(); 
        dict.Add("One", "Chris"); 
        dict.Add("Two", "Steve"); 
        dict.Add("Three", "Messi"); 
        dict.Add("Four", "Ryan"); 
        dict.Add("Five", "Nathan"); 
        Console.WriteLine("तत्वों की संख्या = "+dict.Count); 
        Console.WriteLine("\nकुंजी/मान जोड़े..."); 
        foreach(KeyValuePair<string, string> res in dict){ 
            Console.WriteLine("कुंजी = {0}, मान = {1}", res.Key, res.Value); 
        } 
        if (dict.ContainsValue("Angelina")) 
            Console.WriteLine("मान मिला!"); 
        else 
            Console.WriteLine("मान डिक्शनरी में नहीं है!"); 
        dict.Clear(); 
        Console.WriteLine("साफ़ किए गए कुंजी/मान जोड़े..."); 
        foreach(KeyValuePair<string, string> res in dict){ 
            Console.WriteLine("कुंजी = {0}, मान = {1}", res.Key, res.Value); 
        } 
        Console.WriteLine("अब तत्वों की संख्या = "+dict.Count); 
    } 
}

आउटपुट

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

तत्वों की संख्या = 5 
कुंजी/मान जोड़े... 
कुंजी = One, मान = Chris 
कुंजी = Two, मान = Steve 
कुंजी = Three, मान = Messi 
कुंजी = Four, मान = Ryan 
कुंजी = Five, मान = Nathan 
मान डिक्शनरी में नहीं है! 
साफ़ किए गए कुंजी/मान जोड़े... 
अब तत्वों की संख्या = 0

  1. - C# में Char.IsUpper() मेथड

    C# में Char.IsUpper() मेथड दर्शाता है कि निर्दिष्ट यूनिकोड वर्ण एक अपरकेस अक्षर के रूप में वर्गीकृत है या नहीं। सिंटैक्स public static bool IsUpper (char ch); ऊपर, पैरामीटर ch मूल्यांकन करने के लिए यूनिकोड वर्ण है। आइए अब Char.IsUpper() मेथड को लागू करने का एक उदाहरण देखें - उदाहरण using System; p

  1. - C# में Char.IsSymbol() मेथड

    C# में Char.IsSymbol() मेथड दर्शाता है कि किसी निर्दिष्ट स्ट्रिंग में निर्दिष्ट स्थिति पर वर्ण एक प्रतीक वर्ण के रूप में वर्गीकृत है या नहीं। सिंटैक्स public static bool IsSymbol (string str, int index); ऊपर, str एक स्ट्रिंग है, जबकि str में मूल्यांकन करने के लिए वर्ण की स्थिति। आइए अब Char.IsSymbo

  1. - C# में Dictionary.ContainsKey() मेथड

    C# में Dictionary.ContainsKey() मेथड जांचता है कि Dictionary<TKey, TValue> में निर्दिष्ट कुंजी है या नहीं। सिंटैक्स public bool ContainsKey (TKey key); ऊपर, पैरामीटर key वह कुंजी है जिसे ढूंढा जाना है। आइए अब Dictionary.ContainsKey() मेथड को लागू करने का एक उदाहरण देखें - उदाहरण using System;