हैशटेबल वर्ग के तत्वों की गिनती खोजने के लिए, गणना संपत्ति का उपयोग करें। सबसे पहले, हैशटेबल क्लास को तत्वों के साथ सेट करें -
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"); अब, काउंट प्रॉपर्टी का उपयोग करके तत्वों की संख्या गिनें -
ht.Count
C# में हैशटेबल काउंट प्रॉपर्टी के उपयोग के बारे में जानने के लिए पूरा उदाहरण निम्नलिखित है।
उदाहरण
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