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("Three")); 
        Console.WriteLine("The SortedList object has a fixed size? = " + list.IsFixedSize); 
        Console.WriteLine("Does the SortedList object contains key 10? = " + list.ContainsKey("10")); 
    } 
}

आउटपुट

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

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 
The SortedList object has a fixed size? = False 
Does the SortedList object contains key 10? = False

उदाहरण

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

using System; 
using System.Collections; 
public class Demo { 
    public static void Main(String[] args) { 
        SortedList sortedList = new SortedList(); 
        sortedList.Add("A", "1"); 
        sortedList.Add("B", "2"); 
        sortedList.Add("C", "3"); 
        sortedList.Add("D", "4"); 
        sortedList.Add("E", "5"); 
        sortedList.Add("F", "6"); 
        sortedList.Add("G", "7"); 
        sortedList.Add("H", "8"); 
        sortedList.Add("I", "9"); 
        sortedList.Add("J", "10"); 
        Console.WriteLine("SortedList elements..."); 
        foreach(DictionaryEntry d in sortedList) { 
            Console.WriteLine("Key = " + d.Key + ", Value = " + d.Value); 
        } 
        Console.WriteLine("Count of SortedList key-value pairs = " + sortedList.Count); 
        Console.WriteLine("\nEnumerator to iterate through the SortedList..."); 
        IDictionaryEnumerator demoEnum = sortedList.GetEnumerator(); 
        while (demoEnum.MoveNext()) 
            Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value); 
        Console.WriteLine("Does the SortedList object contains key M? = " + sortedList.ContainsKey("M")); 
        Console.WriteLine("Does the SortedList object contains key H? = " + sortedList.ContainsKey("H")); 
    } 
}

आउटपुट

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

SortedList elements... 
Key = A, Value = 1 
Key = B, Value = 2 
Key = C, Value = 3 
Key = D, Value = 4 
Key = E, Value = 5 
Key = F, Value = 6 
Key = G, Value = 7 
Key = H, Value = 8 
Key = I, Value = 9 
Key = J, Value = 10 
Count of SortedList key-value pairs = 10 
Enumerator to iterate through the SortedList... 
Key = A, Value = 1 
Key = B, Value = 2 
Key = C, Value = 3 
Key = D, Value = 4 
Key = E, Value = 5 
Key = F, Value = 6 
Key = G, Value = 7 
Key = H, Value = 8 
Key = I, Value = 9 
Key = J, Value = 10 
Does the SortedList object contains key M? = False 
Does the SortedList object contains key H? = True

  1. - JavaScript Sets में ऑब्जेक्ट की के लिए सर्च कैसे करें

    JavaScript में Set क्लास एक सेट ऑब्जेक्ट में एलिमेंट्स को खोजने के लिए has मेथड प्रदान करता है। यदि आप किसी ऑब्जेक्ट को सेट में खोजना चाहते हैं, तो आपको उस ऑब्जेक्ट का रेफरेंस प्रदान करना होगा। अलग-अलग मेमोरी एड्रेस वाले समान ऑब्जेक्ट्स को समान नहीं माना जाता। इस मेथड का उपयोग निम्न प्रकार से किया

  1. JavaScript में वेरिएबल से ऑब्जेक्ट की सेट करें JavaScript में वेरिएबल से ऑब्जेक्ट की सेट करें

    वेरिएबल से ऑब्जेक्ट की सेट करने के लिए कोड निम्न है -उदाहरण<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title&g

  1. एक की को छोडकर ऑब्जेक्ट को डीस्ट्रक्चर करना एक की को छोडकर ऑब्जेक्ट को डीस्ट्रक्चर करना

    एक की को छोडकर ऑब्जेक्ट को डीस्ट्रक्चर करने का कोड निम्नलिखित है - उदाहरण <!DOCTYPE html> <html lang=en> <head> <meta charset=UTF-8 /> <meta name=viewport content=width=device-width, initial-scale=1.0 /> <title>Document</title> <style>    b