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

C# में SortedDictionary.Values प्रॉपर्टी - मानों का संग्रह प्राप्त करें

परिचय

C# में SortedDictionary.Values प्रॉपर्टी SortedDictionary<TKey, TValue> में मौजूद सभी मानों (values) का एक संग्रह (collection) वापस करती है। मान कुंजियों (keys) के क्रम में वापस किए जाते हैं।

सिंटैक्स

public System.Collections.Generic.SortedDictionary<TKey,TValue>.ValueCollection Values { get; }

उदाहरण 1: इंटीजर कुंजी और स्ट्रिंग मान

using System;
using System.Collections;
using System.Collections.Generic;

public class Demo {
    public static void Main() {
        SortedDictionary sortedDict = new SortedDictionary();

        sortedDict.Add(1, "Ultrabook");
        sortedDict.Add(2, "Alienware");
        sortedDict.Add(3, "Notebook");
        sortedDict.Add(4, "Connector");
        sortedDict.Add(5, "Flash Drive");
        sortedDict.Add(6, "SSD");
        sortedDict.Add(7, "HDD");
        sortedDict.Add(8, "Earphone");

        Console.WriteLine("SortedDictionary कुंजी-मान जोड़े...");
        IDictionaryEnumerator demoEnum = sortedDict.GetEnumerator();
        while (demoEnum.MoveNext())
            Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);

        Console.WriteLine("\nकुंजी 7 हटाई गई? = " + sortedDict.Remove(7));

        Console.WriteLine("\nSortedDictionary कुंजी-मान जोड़े...अपडेटेड");
        demoEnum = sortedDict.GetEnumerator();
        while (demoEnum.MoveNext())
            Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);

        SortedDictionary.KeyCollection keyList = sortedDict.Keys;
        Console.WriteLine("\nकुंजियों की सूची...");
        foreach (int i in keyList)
            Console.WriteLine(i);

        SortedDictionary.ValueCollection valList = sortedDict.Values;
        Console.WriteLine("\nमानों की सूची...");
        foreach (string s in valList)
            Console.WriteLine(s);
    }
}

आउटपुट

SortedDictionary कुंजी-मान जोड़े...
Key = 1, Value = Ultrabook
Key = 2, Value = Alienware
Key = 3, Value = Notebook
Key = 4, Value = Connector
Key = 5, Value = Flash Drive
Key = 6, Value = SSD
Key = 7, Value = HDD
Key = 8, Value = Earphone

कुंजी 7 हटाई गई? = True

SortedDictionary कुंजी-मान जोड़े...अपडेटेड
Key = 1, Value = Ultrabook
Key = 2, Value = Alienware
Key = 3, Value = Notebook
Key = 4, Value = Connector
Key = 5, Value = Flash Drive
Key = 6, Value = SSD
Key = 8, Value = Earphone

कुंजियों की सूची...
1
2
3
4
5
6
8

मानों की सूची...
Ultrabook
Alienware
Notebook
Connector
Flash Drive
SSD
Earphone

उदाहरण 2: वाहन प्रकारों के साथ

using System;
using System.Collections;
using System.Collections.Generic;

public class Demo {
    public static void Main() {
        SortedDictionary sortedDict = new SortedDictionary();

        sortedDict.Add(1, "SUV");
        sortedDict.Add(2, "MUV");
        sortedDict.Add(3, "Hatchback");
        sortedDict.Add(4, "AUV");
        sortedDict.Add(5, "Convertible");
        sortedDict.Add(6, "Crossover");
        sortedDict.Add(7, "Utility Vehicle");

        Console.WriteLine("SortedDictionary कुंजी-मान जोड़े...");
        IDictionaryEnumerator demoEnum = sortedDict.GetEnumerator();
        while (demoEnum.MoveNext())
            Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);

        Console.WriteLine("\nकुंजी 2 हटाई गई? = " + sortedDict.Remove(2));

        Console.WriteLine("\nSortedDictionary कुंजी-मान जोड़े...अपडेटेड");
        demoEnum = sortedDict.GetEnumerator();
        while (demoEnum.MoveNext())
            Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value);

        SortedDictionary.KeyCollection keyList = sortedDict.Keys;
        Console.WriteLine("\nकुंजियों की सूची...");
        foreach (int i in keyList)
            Console.WriteLine(i);

        SortedDictionary.ValueCollection valList = sortedDict.Values;
        Console.WriteLine("\nमानों की सूची...");
        foreach (string s in valList)
            Console.WriteLine(s);
    }
}

आउटपुट

SortedDictionary कुंजी-मान जोड़े...
Key = 1, Value = SUV
Key = 2, Value = MUV
Key = 3, Value = Hatchback
Key = 4, Value = AUV
Key = 5, Value = Convertible
Key = 6, Value = Crossover
Key = 7, Value = Utility Vehicle

कुंजी 2 हटाई गई? = True

SortedDictionary कुंजी-मान जोड़े...अपडेटेड
Key = 1, Value = SUV
Key = 3, Value = Hatchback
Key = 4, Value = AUV
Key = 5, Value = Convertible
Key = 6, Value = Crossover
Key = 7, Value = Utility Vehicle

कुंजियों की सूची...
1
3
4
5
6
7

मानों की सूची...
SUV
Hatchback
AUV
Convertible
Crossover
Utility Vehicle

मुख्य बिंदु

  • Values प्रॉपर्टी ValueCollection वापस करती है जो IEnumerable<TValue> इम्प्लीमेंट करता है।
  • मान कुंजियों के सॉर्टेड क्रम में वापस किए जाते हैं।
  • संग्रह डायनामिक है - डिक्शनरी में परिवर्तन संग्रह में प्रतिबिंबित होते हैं।
  • केवल पढ़ने योग्य (read-only) - आप इस संग्रह के माध्यम से मान नहीं जोड़/हटा/संशोधित कर सकते।
  1. HTML DOM Meter value प्रॉपर्टी HTML DOM Meter value प्रॉपर्टी

    परिचय HTML DOM Meter value प्रॉपर्टी <meter> एलिमेंट के value एट्रिब्यूट से संबंधित एक नंबर वापस/सेट करती है। बेहतर परिणामों के लिए high, low, min और max एट्रिब्यूट्स के साथ उपयोग करें। नोट: <meter> का उपयोग प्रोग्रेस बार के रूप में न करें बल्कि केवल गेज के रूप में उपयोग करें। सिंटैक्स

  1. HTML DOM nodeValue प्रॉपर्टी HTML DOM nodeValue प्रॉपर्टी

    परिचय HTML DOM nodeValue प्रॉपर्टी नोड के मान से संबंधित एक स्ट्रिंग लौटाती/सेट करती है। सिंटैक्स स्ट्रिंग मान वापस करना: Node.nodeValue यहां, रिटर्न मान निम्न हो सकते हैं: डॉक्यूमेंट नोड्स और एलिमेंट नोड्स के लिए null मान एट्रिब्यूट नोड्स के लिए एट्रिब्यूट का मान टेक्स्ट नोड्स और कमेंट नोड्स के

  1. HTML DOM value प्रॉपर्टी HTML DOM value प्रॉपर्टी

    HTML DOM value प्रॉपर्टी HTML DOM value प्रॉपर्टी एक एलिमेंट के एट्रिब्यूट के मान से संबंधित एक स्ट्रिंग लौटाती है। सिंटैक्स स्ट्रिंग मान प्राप्त करना elementAttribute.value उदाहरण आइए HTML DOM value प्रॉपर्टी का एक उदाहरण देखें: <!DOCTYPE html> <html> <head> <title>HTML