HybridDictionary क्लास (System.Collections.Specialized नेमस्पेस में) छोटे डेटा सेट के लिए ListDictionary और बड़े डेटा सेट के लिए Hashtable के बीच स्वचालित रूप से स्विच करती है। Count प्रॉपर्टी की/वैल्यू पेयर्स की संख्या लौटाती है।
उदाहरण 1: दो HybridDictionaries की गिनती
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary dict1 = new HybridDictionary();
dict1.Add("A", "SUV");
dict1.Add("B", "MUV");
dict1.Add("C", "AUV");
Console.WriteLine("HybridDictionary1 तत्व...");
foreach (DictionaryEntry entry in dict1) {
Console.WriteLine(entry.Key + " " + entry.Value);
}
Console.WriteLine("Dictionary1 में की/वैल्यू पेयर्स की संख्या = " + dict1.Count);
HybridDictionary dict2 = new HybridDictionary();
dict2.Add("1", "One");
dict2.Add("2", "Two");
dict2.Add("3", "Three");
dict2.Add("4", "Four");
dict2.Add("5", "Five");
dict2.Add("6", "Six");
Console.WriteLine("\nHybridDictionary2 तत्व...");
foreach (DictionaryEntry entry in dict2) {
Console.WriteLine(entry.Key + " " + entry.Value);
}
Console.WriteLine("Dictionary2 में की/वैल्यू पेयर्स की संख्या = " + dict2.Count);
// क्लियर करें और फिर गिनें
dict2.Clear();
Console.WriteLine("Dictionary2 क्लियर करने के बाद संख्या = " + dict2.Count);
}
}
आउटपुट
HybridDictionary1 तत्व...
A SUV
B MUV
C AUV
Dictionary1 में की/वैल्यू पेयर्स की संख्या = 3
HybridDictionary2 तत्व...
1 One
2 Two
3 Three
4 Four
5 Five
6 Six
Dictionary2 में की/वैल्यू पेयर्स की संख्या = 6
Dictionary2 क्लियर करने के बाद संख्या = 0
उदाहरण 2: तत्व जोड़ने के बाद गिनती अपडेट
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary dict = new HybridDictionary();
dict.Add("A", "SUV");
dict.Add("B", "MUV");
dict.Add("C", "AUV");
Console.WriteLine("HybridDictionary तत्व...");
foreach (DictionaryEntry entry in dict) {
Console.WriteLine(entry.Key + " " + entry.Value);
}
Console.WriteLine("प्रारंभिक संख्या = " + dict.Count);
// और तत्व जोड़ें
dict.Add("D", "Utility Vehicle");
dict.Add("E", "Convertible");
Console.WriteLine("अपडेटेड संख्या = " + dict.Count);
}
}
आउटपुट
HybridDictionary तत्व...
A SUV
B MUV
C AUV
प्रारंभिक संख्या = 3
अपडेटेड संख्या = 5
मुख्य बातें
Countप्रॉपर्टी वर्तमान आइटम संख्या लौटाती है (O(1) ऑपरेशन)।Clear()सभी आइटम्स हटाता है और Count को 0 कर देता है।HybridDictionaryआंतरिक रूप से आकार के आधार पर ListDictionary/Hashtable चुनता है।- डुप्लिकेट कुंजियों की अनुमति नहीं है - डुप्लिकेट जोड़ने पर एक्सेप्शन फेंका जाता है।