StringDictionary একটি হ্যাশ টেবিল ইমপ্লিমেন্ট করে যেখানে কী এবং ভ্যালু দুটোই স্ট্রিং টাইপের। এটি System.Collections.Specialized নেমস্পেসে আছে।
StringDictionary-এর প্রপার্টিগুলো
| ক্রম | প্রপার্টি ও বর্ণনা |
|---|---|
| 1 | Count — কী/ভ্যালু জোড়ার সংখ্যা। |
| 2 | IsSynchronized — থ্রেড-সেফ কিনা। |
| 3 | Item[String] — নির্দিষ্ট কীর মান পাওয়া/সেট করা। |
| 4 | Keys — সব কীগুলোর কালেকশন। |
| 5 | SyncRoot — সিঙ্ক্রোনাইজেশনের জন্য অবজেক্ট। |
| 6 | Values — সব ভ্যালুগুলোর কালেকশন। |
StringDictionary-এর মেথডসমূহ
| ক্রম | মেথড ও বর্ণনা |
|---|---|
| 1 | Add(String, String) — কী/ভ্যালু জোড়া যোগ করে। |
| 2 | Clear() — সব এন্ট্রি মুছে ফেলে। |
| 3 | ContainsKey(String) — নির্দিষ্ট কী আছে কিনা। |
| 4 | ContainsValue(String) — নির্দিষ্ট ভ্যালু আছে কিনা। |
| 5 | CopyTo(Array, Int32) — ভ্যালুগুলো অ্যারেতে কপি করে। |
উদাহরণ ১: দুটি StringDictionary তুলনা
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary strDict1 = new StringDictionary();
strDict1.Add("A", "John");
strDict1.Add("B", "Andy");
strDict1.Add("C", "Tim");
strDict1.Add("D", "Ryan");
strDict1.Add("E", "Kevin");
strDict1.Add("F", "Katie");
strDict1.Add("G", "Brad");
StringDictionary strDict2 = new StringDictionary();
strDict2.Add("A", "John");
strDict2.Add("B", "Andy");
strDict2.Add("C", "Tim");
strDict2.Add("D", "Ryan");
strDict2.Add("E", "Kevin");
strDict2.Add("F", "Katie");
strDict2.Add("G", "Brad");
StringDictionary strDict3 = new StringDictionary();
strDict3 = strDict2;
Console.WriteLine("Is Dictionary2 equal to Dictionary3? = " + strDict2.Equals(strDict3));
Console.WriteLine("Is Dictionary1 equal to Dictionary3? = " + strDict1.Equals(strDict3));
}
}
আউটপুট
Is Dictionary2 equal to Dictionary3? = True Is Dictionary1 equal to Dictionary3? = False
উদাহরণ ২: IsSynchronized চেক করা
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary strDict1 = new StringDictionary();
strDict1.Add("A", "John");
strDict1.Add("B", "Andy");
strDict1.Add("C", "Tim");
strDict1.Add("D", "Ryan");
strDict1.Add("E", "Kevin");
strDict1.Add("F", "Katie");
strDict1.Add("G", "Brad");
Console.WriteLine("StringDictionary1 elements...");
foreach(DictionaryEntry de in strDict1) {
Console.WriteLine(de.Key + " " + de.Value);
}
StringDictionary strDict2 = new StringDictionary();
strDict2.Add("1", "A");
strDict2.Add("2", "B");
strDict2.Add("3", "C");
strDict2.Add("4", "D");
strDict2.Add("5", "E");
Console.WriteLine("\nStringDictionary2 key-value pairs...");
IEnumerator demoEnum = strDict2.GetEnumerator();
DictionaryEntry d;
while (demoEnum.MoveNext()) {
d = (DictionaryEntry)demoEnum.Current;
Console.WriteLine("Key = " + d.Key + ", Value = " + d.Value);
}
Console.WriteLine("Is the StringDictionary2 synchronized? = " + strDict2.IsSynchronized);
}
}
আউটপুট
StringDictionary1 elements... a John b Andy c Tim d Ryan e Kevin f Katie g Brad StringDictionary2 key-value pairs... Key = 1, Value = A Key = 2, Value = B Key = 3, Value = C Key = 4, Value = D Key = 5, Value = E Is the StringDictionary2 synchronized? = False
নোট
StringDictionary কী-গুলো কেস-ইনসেনসিটিভভাবে স্টোর করে (আউটপুটে ছোট হাতের অক্ষার দেখা যাচ্ছে)।