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

C# में जांचें कि SortedList ऑब्जेक्ट में विशिष्ट मान है या नहीं


यह जांचने के लिए कि क्या SortedList ऑब्जेक्ट में कोई विशिष्ट मान है, कोड इस प्रकार है:

उदाहरण

using System; 
using System.Collections; 
public class Demo { 
    public static void Main(){ 
        SortedList list = new SortedList(); 
        list.Add("1", "One"); 
        list.Add("2", "Two"); 
        list.Add("3", "Three"); 
        list.Add("4", "Four"); 
        list.Add("5", "Five"); 
        list.Add("6", "Six"); 
        list.Add("7", "Seven"); 
        list.Add("8", "Eight"); 
        Console.WriteLine("Key and Value of SortedList...."); 
        foreach(DictionaryEntry k in list ) 
            Console.WriteLine("Key: {0}, Value: {1}", k.Key , k.Value ); 
        Console.WriteLine("Is the SortedList having the value? " + list.ContainsValue("Five")); 
    } 
}

आउटपुट

यह निम्न आउटपुट उत्पन्न करेगा:

Key and Value of SortedList.... 
Key: 1, Value: One 
Key: 2, Value: Two 
Key: 3, Value: Three 
Key: 4, Value: Four 
Key: 5, Value: Five 
Key: 6, Value: Six 
Key: 7, Value: Seven 
Key: 8, Value: Eight 
Is the SortedList having the value? True

उदाहरण

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

using System; 
using System.Collections; 
public class Demo { 
    public static void Main(){ 
        SortedList list = new SortedList(); 
        list.Add("1", "One"); 
        list.Add("2", "Two"); 
        list.Add("3", "Three"); 
        list.Add("4", "Four"); 
        list.Add("5", "Five"); 
        list.Add("6", "Six"); 
        list.Add("7", "Seven"); 
        list.Add("8", "Eight"); 
        Console.WriteLine("Key and Value of SortedList...."); 
        foreach(DictionaryEntry k in list ) 
            Console.WriteLine("Key: {0}, Value: {1}", k.Key , k.Value ); 
        Console.WriteLine("Is the SortedList having the value? " + list.ContainsValue("Tenth")); 
    } 
}

आउटपुट

यह निम्न आउटपुट उत्पन्न करेगा:

Key and Value of SortedList.... 
Key: 1, Value: One 
Key: 2, Value: Two 
Key: 3, Value: Three 
Key: 4, Value: Four 
Key: 5, Value: Five 
Key: 6, Value: Six 
Key: 7, Value: Seven 
Key: 8, Value: Eight 
Is the SortedList having the value? False
  1. - C# में Hashtable में किसी विशिष्ट कुंजी की जांच कैसे करें

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

  1. - C# में SortedSet में किसी विशिष्ट तत्व की जांच कैसे करें

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

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

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