---
title: "What is HashTable?"  
description: "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"  
author: "Uttam Misra"  
published: 2010-11-01  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/40/what-is-hashtable  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# What is HashTable?

[Hashtable in C#](https://www.mindstick.com/forum/33627/how-to-use-hashtable-in-c-sharp-dot-net) represents a [collection](https://www.mindstick.com/articles/1718/collections-in-java) of key/[value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) pairs which maps keys to value. Any non-null object can be used as a key but a value can. We can [retrieve](https://www.mindstick.com/forum/34400/how-to-retrieve-form-values-in-controller-action) [items](https://www.mindstick.com/articles/44359/store-your-valuable-items-in-a-mini-storage-unit) from hashTable to provide the key. Both keys and [values](https://www.mindstick.com/forum/327/sum-textbox-values) are Objects.\

##### The commonly used functions in Hashtable are:

· Add : To add a pair of value in HashTable

· ContainsKey : [Check if](https://www.mindstick.com/forum/12878/how-to-check-if-an-asp-dot-net-file-upload-control-has-a-file-in-jquery) a specified key exist or not

· ContainsValue : Check the specified Value exist in HashTable

· [Remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden) : 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](https://www.mindstick.com/blog/301883/why-you-shouldn-t-trust-ai-search-engines) 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");

---

Original Source: https://www.mindstick.com/blog/40/what-is-hashtable

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
