Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Keys property of Hashtable class in C#?
Gets an ICollection containing the keys in the Hashtable. It displays all the keys in the collection. In the below code, to get all the keys we have used a loop to loop through the collection.
foreach (int k in h.Keys) {
Console.WriteLine(k);
}
The above displays all the keys as shown in the following code −
Example
using System;
using System.Collections;
class Program {
static void Main() {
Hashtable h = new Hashtable();
h.Add(1, "India");
h.Add(2, "US");
h.Add(3, "UK");
h.Add(4, "Australia");
h.Add(5, "Netherland");
foreach (int k in h.Keys) {
Console.WriteLine(k);
}
}
}
Output
5 4 3 2 1
Advertisements