Use foreach statement to loop through all keys in a hashtable : Hashtable : Data Structure C# Examples


C# Examples » Data Structure » Hashtable »

 

Use foreach statement to loop through all keys in a hashtable









    
using  System;
using  System.Collections;

class  MainClass
{
        public  static  void  Main()
        {
                Hashtable        hash  =  new  Hashtable();
                hash.Add("A",  "1");
                hash.Add("B",  "2");
                hash.Add("C",  "3");
                hash.Add("D",  "4");
                hash.Add("E",  "5");
                
                foreach  (string  firstName  in  hash.Keys)
                {
                        Console.WriteLine("{0}  {1}",  firstName,  hash[firstName]);
                }
        }
}
    
   
  
   



Output

A 1
B 2
C 3
D 4
E 5


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Hashtable