Implement Hashtable in C#

By Sourav Kayal Jun 29, 2013
Here i am going to show how to use hashtable in c#

Hash Table

HashTable  class is one of Collection class of .NET Class library. You have to include

using System.Collections;

 namespace in order to use collection class in your program.

HashTable use key value pair to store data in Object. In HashTable it's very easy to search any value as HashTable maintain key to identify specific value.

Here i have given full example of hash table

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections;

namespace BlogProject


    class Program


        static void Main(string[] args)


            Hashtable hashtable = new Hashtable();

            hashtable[1] = "One";

            hashtable[2] = "Two";

            hashtable[13] = "Thirteen";

            foreach (DictionaryEntry entry in hashtable)


                Console.WriteLine("{0}, {1}", entry.Key, entry.Value);






 Here within for each loop I am displaying all value of item using key.

Sourav Kayal

I am .NET learner passionate logger, like to .NET eat and sleep.  Have little experience in Web technology with new development platform including node.js, MVC Web API. Feel free to teach me .NET.