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

Ebook Download
View all
Learn
View all