Implement Hashtable in C#

By Sourav Kayal Blogs | .NET 4.5 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.



Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs