হ্যাশটেবল ক্লাসের উপাদানগুলির গণনা খুঁজে পেতে, গণনা সম্পত্তি ব্যবহার করুন। প্রথমত, Hashtable ক্লাসটি উপাদান সহ সেট করুন −
Hashtable ht = new Hashtable();
ht.Add("One", "Tom");
ht.Add("Two", "Jack");
ht.Add("Three", "Peter");
ht.Add("Four", "Russel");
ht.Add("Five", "Brad");
ht.Add("Six", "Bradley");
ht.Add("Seven", "Steve");
ht.Add("Eight", "David"); এখন, Count প্রপার্টি −
ব্যবহার করে উপাদানের সংখ্যা গণনা করুনht.Count
C# এ Hashtable Count প্রপার্টির ব্যবহার সম্পর্কে জানতে নিচের সম্পূর্ণ উদাহরণ।
উদাহরণ
using System;
using System.Collections;
namespace Demo {
class Program {
static void Main(string[] args) {
Hashtable ht = new Hashtable();
ht.Add("One", "Tom");
ht.Add("Two", "Jack");
ht.Add("Three", "Peter");
ht.Add("Four", "Russel");
ht.Add("Five", "Brad");
ht.Add("Six", "Bradley");
ht.Add("Seven", "Steve");
ht.Add("Eight", "David");
Console.WriteLine("Count = " + ht.Count);
Console.ReadKey();
}
}
} আউটপুট
Count = 8