- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the Count property of Hashtable class in C#?
To find the count of elements of Hashtable class, use the Count property. Firstly, set the Hashtable class with elements −
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");
Now, count the number of elements using the Count property −
ht.Count
The following is the complete example to learn about the usage of Hashtable Count property in C#.
Example
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(); } } }
Output
Count = 8
Advertisements