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

C# में OrderedDictionary में IDictionaryEnumerator ऑब्जेक्ट प्राप्त करें

OrderedDictionary.GetEnumerator() मेथड एक IDictionaryEnumerator लौटाता है जो कुंजी-मान जोड़ों पर सम्मिलन क्रम में पुनरावृत्ति करता है। यह DictionaryEntry ऑब्जेक्ट्स के माध्यम से कुंजियों और मानों दोनों तक पहुंच प्रदान करता है।

उदाहरण 1: संख्यात्मक कुंजियाँ

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

public class Demo
{
    public static void Main()
    {
        OrderedDictionary dict = new OrderedDictionary();
        dict.Add("1", "One");
        dict.Add("2", "Two");
        dict.Add("3", "Three");
        dict.Add("4", "Four");
        dict.Add("5", "Five");
        dict.Add("6", "Six");
        dict.Add("7", "Seven");
        dict.Add("8", "Eight");
        IDictionaryEnumerator demoEnum = dict.GetEnumerator();
        while (demoEnum.MoveNext())
        {
            Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
        }
    }
}

आउटपुट

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

उदाहरण 2: श्रेणी कुंजियाँ

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

public class Demo
{
    public static void Main()
    {
        OrderedDictionary dict = new OrderedDictionary();
        dict.Add("1", "Appliances");
        dict.Add("2", "Supplies");
        dict.Add("3", "Electronics");
        dict.Add("4", "Clothing");
        dict.Add("5", "Books");
        dict.Add("6", "Accessories");
        IDictionaryEnumerator demoEnum = dict.GetEnumerator();
        while (demoEnum.MoveNext())
        {
            Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);
        }
    }
}

आउटपुट

Key = 1, Value = Appliances
Key = 2, Value = Supplies
Key = 3, Value = Electronics
Key = 4, Value = Clothing
Key = 5, Value = Books
Key = 6, Value = Accessories

OrderedDictionary सम्मिलन क्रम बनाए रखता है। IDictionaryEnumerator Key, Value, Entry गुण प्रदान करता है। आधुनिक कोड में foreach (var kvp in dict) (जो IEnumerable<DictionaryEntry> लागू करता है) पसंद किया जाता है।

  1. - C# में OrderedDictionary की रीड-ओनली कॉपी प्राप्त करें

    उदाहरण OrderedDictionary की AsReadOnly() मेथड डिक्शनरी का एक रीड-ओनली रैपर लौटाती है। यह रैपर IsReadOnly प्रॉपर्टी को true पर सेट करता है, जिससे डिक्शनरी में संशोधन रोका जाता है। using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void

  1. - C# में OrderedDictionary में मानों को समाहित करने वाला ICollection प्राप्त करें

    OrderedDictionary में मानों को समाहित करने वाला ICollection प्राप्त करने के लिए, कोड इस प्रकार है: उदाहरण using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ OrderedDictionary dict = new OrderedDictionary();

  1. - JavaScript में ऑब्जेक्ट के मान कैसे प्राप्त करें?

    Object.values() जैसे कुछ तरीके हैं जिनसे किसी ऑब्जेक्ट के मान प्राप्त किए जा सकते हैं। लेकिन उन तरीकों के माध्यम से, मानों को खोजने की प्रक्रिया लंबी है। इसे कम करने के लिए, Underscore.js जावास्क्रिप्ट की एक लाइब्रेरी ने _.values() नामक एक विधि प्रदान की है। इस विधि को मानों को निष्पादित करने के लि