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

C# में HybridDictionary की कुंजियों का ICollection प्राप्त करें

उदाहरण

HybridDictionary की Keys प्रॉपर्टी एक ICollection लौटाती है जिसमें सभी कुंजियाँ होती हैं। इस उदाहरण में कुंजियों को एक स्ट्रिंग ऐरे में कॉपी करके प्रिंट किया गया है।

using System;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        HybridDictionary dict = new HybridDictionary();
        dict.Add("One", "Katie");
        dict.Add("Two", "Andy");
        dict.Add("Three", "Gary");
        dict.Add("Four", "Mark");
        dict.Add("Five", "Marie");
        dict.Add("Six", "Sam");
        dict.Add("Seven", "Harry");
        dict.Add("Eight", "Kevin");
        dict.Add("Nine", "Ryan");

        String[] strArr = new String[dict.Count];
        dict.Keys.CopyTo(strArr, 0);

        for (int i = 0; i < dict.Count; i++)
            Console.WriteLine(strArr[i]);
    }
}

आउटपुट

Eight
Seven
Four
Three
One
Five
Six
Two
Nine

एक और उदाहरण

using System;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        HybridDictionary dict = new HybridDictionary();
        dict.Add("1", "A");
        dict.Add("2", "B");
        dict.Add("3", "C");
        dict.Add("4", "D");
        dict.Add("5", "E");
        dict.Add("6", "F");

        String[] strArr = new String[dict.Count];
        dict.Keys.CopyTo(strArr, 0);

        for (int i = 0; i < dict.Count; i++)
            Console.WriteLine(strArr[i]);
    }
}

आउटपुट

1
2
3
4
5
6
  1. - C# में SortedList Class की Keys Property क्या है?

    SortedList में Keys को SortedList Class की Keys Property का उपयोग करके Get करें। हमने पहले SortedList Property को Elements के साथ Set किया है।SortedList sl = new SortedList(); sl.Add(ST0, One); sl.Add(ST1, Two); sl.Add(ST2, Three); sl.Add(ST3, Four); sl.Add(ST4, Five); sl.Add(ST5, Six); sl.Add(ST6,

  1. - C# में List.GetRange() से तत्वों की रेंज प्राप्त करना

    C# में List<T>.GetRange() मेथड का उपयोग करके सूची के एक सन्निकट (contiguous) भाग को एक नई सूची के रूप में प्राप्त किया जा सकता है। यह ArraySegment या LINQ के Skip()/Take() के समान है लेकिन सूची-विशिष्ट है। उदाहरण using System; using System.Collections.Generic; public class Demo { public

  1. - C# में Dictionary से कुंजियों (Keys) की सूची प्राप्त करना

    C# में Dictionary<TKey, TValue> से सभी कुंजियों (keys) को एक सूची (List<TKey>) के रूप में प्राप्त करने के लिए Keys प्रॉपर्टी का उपयोग करके कंस्ट्रक्टर या ToList() मेथड का उपयोग किया जाता है। उदाहरण using System; using System.Collections.Generic; public class Demo { public static v