Articles → .NET → Hashtable in C#

Hashtable in C#






Key-value pair






DaysPlaces
Day 1Place 1
Day 2Place 2
Day 3Place 3
Day 4Place 3













Hashtable





Syntax


Hashtable objectHashtable = new Hashtable();



Example


using System;
using System.Collections;
using System.Collections.Generic;

namespace Test1 {
  class Program {
    static void Main(string[] args) {
      Hashtable table = new Hashtable();
      table.Add("Day 1", "Place 1");
      table.Add("Day 2", "Place 2");
      table.Add("Day 3", "Place 3");
      table.Add("Day 4", "Place 3");

      Console.WriteLine("Looping");

      foreach(DictionaryEntry pair in table) {
        Console.WriteLine(pair.Key + "--" + pair.Value);
      }

      Console.ReadLine();

    }
  }
}



Output


Picture showing the output of hashtable in C#

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, December 21, 2016

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250