HybridDictionary कंस्ट्रक्टर एक बूलियन पैरामीटर स्वीकार करता है जो केस संवेदनशीलता निर्दिष्ट करता है: true केस-सेंसिटिव (डिफ़ॉल्ट), false केस-इनसेंसिटिव। यह छोटे डेटा के लिए ListDictionary और बड़े के लिए Hashtable का उपयोग करता है।
उदाहरण 1: डिफ़ॉल्ट (केस-सेंसिटिव)
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo
{
public static void Main()
{
HybridDictionary myDict = new HybridDictionary();
myDict.Add("A", "AB");
myDict.Add("B", "BC");
myDict.Add("C", "DE");
myDict.Add("D", "FG");
myDict.Add("e", "fg");
Console.WriteLine("Key/Value pairs...");
foreach (DictionaryEntry de in myDict)
Console.WriteLine("Key = " + de.Key + ", Value = " + de.Value);
}
}
आउटपुट
Key/Value pairs... Key = A, Value = AB Key = B, Value = BC Key = C, Value = DE Key = D, Value = FG Key = e, Value = fg
उदाहरण 2: मिश्रित केस कुंजियाँ
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo
{
public static void Main()
{
HybridDictionary myDict = new HybridDictionary();
myDict.Add("A", "PQ");
myDict.Add("B", "BC");
myDict.Add("C", "tu");
myDict.Add("D", "FG");
myDict.Add("d", "gh");
myDict.Add("e", "fg");
Console.WriteLine("Key/Value pairs...");
foreach (DictionaryEntry de in myDict)
Console.WriteLine("Key = " + de.Key + ", Value = " + de.Value);
}
}
आउटपुट
Key/Value pairs... Key = A, Value = PQ Key = B, Value = BC Key = C, Value = tu Key = D, Value = FG Key = d, Value = gh Key = e, Value = fg
डिफ़ॉल्ट कंस्ट्रक्टर केस-सेंसिटिव तुलना का उपयोग करता है (कुंजियाँ "D" और "d" अलग हैं)। केस-इनसेंसिटिव के लिए new HybridDictionary(false) पास करें। HybridDictionary IDictionary लागू करता है और स्वचालित रूप से आंतरिक कार्यान्वयन को आकार के आधार पर स्विच करता है।