StringDictionary সিঙ্ক্রোনাইজড (থ্রেড-সেফ) কিনা যাচাই করতে নিচের কোডটি ব্যবহার করা হয়:
উদাহরণ ১
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 এলিমেন্ট...");
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 কী-ভ্যালু জোড়া...");
IEnumerator demoEnum = strDict2.GetEnumerator();
DictionaryEntry d;
while (demoEnum.MoveNext()) {
d = (DictionaryEntry)demoEnum.Current;
Console.WriteLine("Key = " + d.Key + ", Value = " + d.Value);
}
Console.WriteLine("StringDictionary2 সিঙ্ক্রোনাইজড কি? = " + strDict2.IsSynchronized);
}
}
আউটপুট
এটি নিচের আউটপুটটি তৈরি করবে:
StringDictionary1 এলিমেন্ট... a John b Andy c Tim d Ryan e Kevin f Katie g Brad StringDictionary2 কী-ভ্যালু জোড়া... Key = 1, Value = A Key = 2, Value = B Key = 3, Value = C Key = 4, Value = D Key = 5, Value = E StringDictionary2 সিঙ্ক্রোনাইজড কি? = False
উদাহরণ ২
আরেকটি উদাহরণ দেখি:
using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringDictionary strDict = new StringDictionary();
strDict.Add("One", "Laptop");
strDict.Add("Two", "Desktop");
strDict.Add("Three", "Earphone");
strDict.Add("Four", "Speaker");
strDict.Add("Five", "HardDisk");
strDict.Add("Six", "SSD");
strDict.Add("Seven", "HardDisk");
Console.WriteLine("StringDictionary কী-ভ্যালু জোড়া...");
IEnumerator demoEnum = strDict.GetEnumerator();
DictionaryEntry d;
while (demoEnum.MoveNext()) {
d = (DictionaryEntry)demoEnum.Current;
Console.WriteLine("Key = " + d.Key + ", Value = " + d.Value);
}
Console.WriteLine("StringDictionary সিঙ্ক্রোনাইজড কি? = " + strDict.IsSynchronized);
}
}
আউটপুট
এটি নিচের আউটপুটটি তৈরি করবে:
StringDictionary কী-ভ্যালু জোড়া... Key = five, Value = HardDisk Key = one, Value = Laptop Key = four, Value = Speaker Key = three, Value = Earphone Key = seven, Value = HardDisk Key = six, Value = SSD Key = two, Value = Desktop StringDictionary সিঙ্ক্রোনাইজড কি? = False