Hashtable-এ কীগুলোর ICollection পেতে নিচের কোডটি ব্যবহার করা হয়:
উদাহরণ ১
using System;
using System.Collections;
public class Demo {
public static void Main() {
Hashtable hash = new Hashtable();
hash.Add("A", "ইলেক্ট্রনিক্স");
hash.Add("B", "অ্যাপ্লায়েন্স");
hash.Add("C", "পেট সাপ্লাই");
hash.Add("D", "বই");
hash.Add("E", "খেলনা");
hash.Add("F", "ফুটওয়্যার");
hash.Add("G", "পোশাক");
ICollection col = hash.Keys;
foreach(string str in col)
Console.WriteLine(str + ": " + hash[str]);
}
}
আউটপুট
এটি নিচের আউটপুটটি তৈরি করবে:
G: পোশাক A: ইলেক্ট্রনিক্স B: অ্যাপ্লায়েন্স C: পেট সাপ্লাই D: বই E: খেলনা F: ফুটওয়্যার
উদাহরণ ২
আরেকটি উদাহরণ দেখি:
using System;
using System.Collections;
public class Demo {
public static void Main() {
Hashtable hash = new Hashtable();
hash.Add(1, "AB");
hash.Add(2, "CD");
hash.Add(3, "EF");
hash.Add(4, "GH");
hash.Add(5, "IJ");
hash.Add(6, "KL");
hash.Add(7, "MN");
ICollection col = hash.Keys;
foreach(int str in col)
Console.WriteLine("Key = " + str + ", Value = " + hash[str]);
}
}
আউটপুট
এটি নিচের আউটপুটটি তৈরি করবে:
Key = 7, Value = MN Key = 6, Value = KL Key = 5, Value = IJ Key = 4, Value = GH Key = 3, Value = EF Key = 2, Value = CD Key = 1, Value = AB