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

C# में ListDictionary के मानों का ICollection प्राप्त करें

उदाहरण

ListDictionary की Values प्रॉपर्टी एक ICollection लौटाती है जिसमें सभी मान होते हैं। इस उदाहरण में मानों को फोरईच लूप के माध्यम से प्रिंट किया गया है।

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

public class Demo {
    public static void Main() {
        ListDictionary listDict = new ListDictionary();
        listDict.Add("1", "Laptop");
        listDict.Add("2", "Tablet");
        listDict.Add("3", "Desktop");
        listDict.Add("4", "Speaker");
        listDict.Add("5", "Earphone");
        listDict.Add("6", "Headphone");

        ICollection col = listDict.Values;
        foreach(String s in col) {
            Console.WriteLine(s);
        }
    }
}

आउटपुट

Laptop
Tablet
Desktop
Speaker
Earphone
Headphone

एक और उदाहरण

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

public class Demo {
    public static void Main() {
        ListDictionary listDict = new ListDictionary();
        listDict.Add("A", "Tom");
        listDict.Add("B", "John");
        listDict.Add("C", "Kevin");
        listDict.Add("D", "Tim");

        ICollection col = listDict.Values;
        foreach(String s in col) {
            Console.WriteLine(s);
        }
    }
}

आउटपुट

Tom
John
Kevin
Tim
  1. - C# में StringDictionary के मानों का कलेक्शन प्राप्त करें

    उदाहरण StringDictionary की Keys प्रॉपर्टी कुंजियों का ICollection लौटाती है। मानों को कुंजी के माध्यम से एक्सेस किया जा सकता है। इस उदाहरण में कुंजियों को ऐरे में कॉपी करके कुंजी-मान जोड़े प्रिंट किए गए हैं। using System; using System.Collections; using System.Collections.Specialized; public class

  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. - C# में List.GetRange() से तत्वों की रेंज प्राप्त करना

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