The HashTable is related to System.Collections namespace. The HashTable contains on key-value pairs. Where each key is associated with a unique value.
You will use System.Collections namespace for creating The hashtable. The below code is syntax of creating the hashtable.
A HashTable contains the key-value pairs and for making key-value pairs you can use Add method. The key must be unique in each key-value pairs in Add method.
You can retrieve values by their associated keys:
You can remove key-value pairs by their key:
You can check if a key exists in the HashTable using the Contains method:
// Returns false after removing "FruitPrice";
// Returns false after removing "FruitPrice";
You can use the DictionaryEntry structure to iterate through the key-value pairs:
The HashTable class also provides methods and properties for checking the number of key-value pairs, clearing the HashTable, and more.
// Removes all key-value pairs
// Removes all key-value pairs
HashTable is collection of Key-Value pairs. In Key-Value pairs, each key must be unique. HashTable can store any type (int, float, string, bool) of data.