
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- What is the IsReadOnly property of Hashtable class in C#?
- What is the IsFixedSize property of Hashtable class in C#?
- What is the Item property of Hashtable class in C#?
- What is the Count property of Hashtable class in C#?
- What is the Values property of Hashtable class in C#?
- What is the Keys property of SortedList class in C#?
- What is the Hashtable class in C#?
- The HashTable Class in Javascript
- Get an ICollection containing the keys in the Hashtable C#
- How to get keys from a HashTable in C#?
- What is the Item property of ArrayList class in C#?
- What is the IsReadOnly property of BitArray class in C#?
- What is the IsFixedSize property of SortedList class in C#?
- What is the IsReadOnly property of SortedList class in C#?
- What is the Item property of SortedList class in C#?

Advertisements