C# Collections Part 2: Hashtable

Hashtable:

  • Key/Value combination. (Keys are user defined)
  • Variable length
  • Type independent
Code:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using System.Collections;  
  7.   
  8. namespace hashTable  
  9. {  
  10.     class Program  
  11.     {  
  12.         static void Main(string[] args)  
  13.         {  
  14.             Hashtable ht = new Hashtable();  
  15.             ht.Add("Eid",101);  
  16.             ht.Add("Ename","Abdullah Al Hasan");  
  17.             ht.Add("Email","sujanhasan38@gmail.com");  
  18.             ht.Add("Dname","CSE");  
  19.             print(ht);  
  20.               
  21.             Console.ReadLine();  
  22.         }  
  23.   
  24.         public static void print(Hashtable htable)  
  25.         {  
  26.             foreach (var i in htable.Keys)  
  27.             {  
  28.                 Console.WriteLine(i+" : "+htable[i]);  
  29.             }  
  30.         }  
  31.     }  
  32. }  
Share:

0 Comments:

Post a Comment