Home > DeveloperSection > Blogs > What is HashTable?

What is HashTable?


C# C# 
Ratings:
0 Comment(s)
 1717  View(s)
Rate this:

HashTable in C#.Net

Hashtable in C# represents a collection of key/value pairs which maps keys to value. Any non-null object can be used as a key but a value can. We can retrieve items from hashTable to provide the key. Both keys and values are Objects.

The commonly used functions in Hashtable are:

·         Add                        : To add a pair of value in HashTable

·         ContainsKey       : Check if a specified key exist or not

·         ContainsValue   : Check the specified Value exist in HashTable

·         Remove               : Remove the specified Key and corresponding Value

Add : To add a pair of value in HashTable

  Syntax : HashTable.Add(Key,Value)

  Key : The Key value

  Value : The value of corresponding key

  Hashtable ht;

  ht.Add("1", "Sunday");

ContainsKey : Check if a specified key exist or not

  Synatx : bool HashTable.ContainsKey(key)

  Key                      : The Key value for search in HahTable

  Returns : return true if item exist else false

  ht.Contains("1");

ContainsValue : Check the specified Value exist in HashTable

  Synatx : bool HashTable.ContainsValue(Value)

  Value : Search the specified Value in HashTable

  Returns : return true if item exist else false

  ht.ContainsValue("Sunday")

Remove : Remove the specified Key and corresponding Value

  Syntax : HashTable.Remove(Key)

  Key : The key of the element to remove

  ht.Remove("1");

 


Don't want to miss updates? Please click the below button!

Follow MindStick