---
title: "What are the uses of HashTable in C# Explain with example?"  
description: "What are the uses of HashTable in C# Explain with example?"  
author: "Ethan Karla"  
published: 2021-08-27  
canonical: https://answers.mindstick.com/qa/93935/what-are-the-uses-of-hashtable-in-c-sharp-explain-with-example  
category: "programming"  
tags: ["c#", "java programming", "java"]  
reading_time: 1 minute  

---

# What are the uses of HashTable in C# Explain with example?

What are the uses of [HashTable in C#](https://www.mindstick.com/forum/33627/how-to-use-hashtable-in-c-sharp-dot-net) [Explain](https://yourviews.mindstick.com/view/86025/content-created-for-humans-not-for-bots-explain-this-statement) with example?

## Answers

### Answer by Ravi Vishwakarma

**Hashtable** is a non-generic collection class, which stores data in the key, value pair of different datatype. hashtable is the same as the dictionary object, but the difference between hashtable and dictionary is, a hashtable is stores different datatype and dictionaries are stored the same type of data. Hashtable will provide lower performance because it supports the heterogeneous datatype.

**Example**

```
using System;
using System.Collections;
public class Program
{
 public static void Main()
 {
  Hashtable htbl = new Hashtable();
  htbl.Add(5,'Five');
  htbl.Add(1,'One');
  htbl.Add(2,'Two');
  htbl.Add(3,'Three');
  htbl.Add(4,'Four');
  foreach(DictionaryEntry  item in htbl)
   Console.WriteLine('Key : ' + item.Key + ' Value : '+item.Value);
 }
}
```

## Output

```
Key : 5 Value : Five
Key : 4 Value : Four
Key : 3 Value : Three
Key : 2 Value : Two
Key : 1 Value : One
```

\


---

Original Source: https://answers.mindstick.com/qa/93935/what-are-the-uses-of-hashtable-in-c-sharp-explain-with-example

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
