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