Blog

Implement Hashtable in C#

Posted 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);

            }

            Console.ReadLine();

        }

    }

}

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

COMMENT USING
PREMIUM SPONSORS
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.