Blog

Implement Hashtable in C#

Jun 29, 2013 Blogs | .NET 4.5
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.

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...

  • 23rank
  • 1M readers
  • 2times
COMMENT USING

PREMIUM SPONSORS

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