परिचय
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) - आप इस संग्रह के माध्यम से मान नहीं जोड़/हटा/संशोधित कर सकते।