Hash Table


using System;
using System.Collections;

class HashTable
{

    static void Main(string[] args)
    {
        Hashtable hash = new Hashtable();   // Declaring a Hash table

        // Adding values as key-value pairs using Add method. First parameter is the key and second parameter is the value.
        hash.Add("1",1);    
        hash.Add("2"2);
        hash.Add("3"3);
        hash.Add("4"4);

        // For displaying values in a Hashtable,we can use a foreach loop
        int limit = hash.Count;   // Gets the size of Hash table
        Console.WriteLine("Using foreach loop");
        foreach (string i in hash.Keys)
        {
            Console.WriteLine(hash[i]);
        }
        
        Console.ReadLine();

    }
}

Output:
Using foreach loop
1
2
3
4