Implement Hashtable in C#

Here i am going to show how to use hashtable in c#. 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.

Hash Table
 
HashTable class is one of Collection class of .NET Class library. You have to include
  1. 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
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Collections;  
  6. namespace BlogProject  
  7. {  
  8.     class Program  
  9.     {  
  10.         static void Main(string[] args)  
  11.         {  
  12.             Hashtable hashtable = new Hashtable();  
  13.             hashtable[1] = "One";  
  14.             hashtable[2] = "Two";  
  15.             hashtable[13] = "Thirteen";  
  16.             foreach (DictionaryEntry entry in hashtable)  
  17.             {  
  18.                 Console.WriteLine("{0}, {1}", entry.Key, entry.Value);  
  19.             }  
  20.             Console.ReadLine();  
  21.         }  
  22.     }  
  23. }  
Here within for each loop I am displaying all value of item using key.
 
Hash Table