Articles → CSHARP → Hashtable In C#

Hashtable In C#






Key-Value Pair






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






  1. There is a mapping between days and places in itinerary.
  2. Days are unique and from the days you can find the place you visit on that particular day (not vice versa).



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