HybridDictionary ক্লাস IDictionary ইমপ্লিমেন্ট করে। এটি ছোট কালেকশনে ListDictionary (লিঙ্কড লিস্ট) ব্যবহার করে এবং আকার বড় হলে স্বয়ংক্রিয়ভাবে Hashtable-এ স্বিচ করে। এটি পারফরম্যান্স অপ্টিমাইজেশনের জন্য ডিজাইন করা।
HybridDictionary-এর প্রপার্টিগুলো
| ক্রম | প্রপার্টি ও বর্ণনা |
| 1 | Count — কী/ভ্যালু জোড়ার সংখ্যা। |
| 2 | IsFixedSize — ফিক্সড সাইজ কিনা। |
| 3 | IsReadOnly — রিড-অনলি কিনা। |
| 4 | IsSynchronized — থ্রেড-সেফ কিনা (সবসময় false)। |
| 5 | Item[Object] — নির্দিষ্ট কীর মান পাওয়া/সেট করা। |
| 6 | Keys — সব কীগুলোর কালেকশন। |
| 7 | SyncRoot — সিঙ্ক্রোনাইজেশনের জন্য অবজেক্ট। |
| 8 | Values — সব ভ্যালুগুলোর কালেকশন। |
HybridDictionary-এর মেথডসমূহ
| ক্রম | মেথড ও বর্ণনা |
| 1 | Add(Object, Object) — কী/ভ্যালু জোড়া যোগ করে। |
| 2 | Clear() — সব এন্ট্রি মুছে ফেলে। |
| 3 | Contains(Object) — নির্দিষ্ট কী আছে কিনা। |
| 4 | CopyTo(Array, Int32) — এন্ট্রিগুলো অ্যারেতে কপি করে। |
| 5 | GetEnumerator() — IDictionaryEnumerator রিটার্ন করে। |
উদাহরণ ১: Count প্রপার্টি ও Clear()
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 elements...");
foreach(DictionaryEntry d in dict1) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("Count of Key/value pairs in 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 elements...");
foreach(DictionaryEntry d in dict2) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("Count of Key/value pairs in Dictionary2 = " + dict1.Count); // বাগ: dict2.Count হওয়া উচিত
dict2.Clear();
Console.WriteLine("Count of Key/value pairs in Dictionary2 (Updated) = " + dict2.Count);
}
}
আউটপুট
HybridDictionary1 elements...
A SUV
B MUV
C AUV
Count of Key/value pairs in Dictionary1 = 3
HybridDictionary2 elements...
1 One
2 Two
3 Three
4 Four
5 Five
Six
Count of Key/value pairs in Dictionary2 = 3
Count of Key/value pairs in Dictionary2 (Updated) = 0
উদাহরণ ২: প্রপার্টি চেক করা
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
HybridDictionary dict1 = new HybridDictionary();
dict1.Add("A", "Books");
dict1.Add("B", "Electronics");
dict1.Add("C", "Smart Wearables");
dict1.Add("D", "Pet Supplies");
dict1.Add("E", "Clothing");
dict1.Add("F", "Footwear");
Console.WriteLine("HybridDictionary1 elements...");
foreach(DictionaryEntry d in dict1) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("Is the HybridDictionary1 having fixed size? = " + dict1.IsFixedSize);
Console.WriteLine("If HybridDictionary1 read-only? = " + dict1.IsReadOnly);
Console.WriteLine("Is HybridDictionary1 synchronized = " + dict1.IsSynchronized);
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 elements...");
foreach(DictionaryEntry d in dict2) {
Console.WriteLine(d.Key + " " + d.Value);
}
Console.WriteLine("Is HybridDictionary1 equal to HybridDictionary2? = " + (dict1.Equals(dict2)));
Console.WriteLine("Is the HybridDictionary2 having fixed size? = " + dict2.IsFixedSize);
Console.WriteLine("If HybridDictionary2 read-only? = " + dict2.IsReadOnly);
Console.WriteLine("Is HybridDictionary2 synchronized = " + dict2.IsSynchronized);
}
}
আউটপুট
HybridDictionary1 elements...
A Books
B Electronics
C Smart Wearables
D Pet Supplies
E Clothing
F Footwear
Is the HybridDictionary1 having fixed size? = False
If HybridDictionary1 read-only? = False
Is HybridDictionary1 synchronized = False
HybridDictionary2 elements...
1 One
2 Two
3 Three
4 Four
5 Five
6 Six
Is HybridDictionary1 equal to HybridDictionary2? = False
Is the HybridDictionary2 having fixed size? = False
If HybridDictionary2 read-only? = False
Is HybridDictionary2 synchronized = False
গুরুত্বপূর্ণ টিপস
- ১০-১৫ এলিমেন্টের নিচে ListDictionary, তার উপরে Hashtable ব্যবহার করে।
Equals রেফারেন্স সমতা চেক করে, কন্টেন্ট নয়।
- সিঙ্ক্রোনাইজেশন জন্য
lock(dict.SyncRoot) ব্যবহার করুন।