Articles → CSHARP → Hashtable In C#
Hashtable In C#
Key-Value Pair
Days | Places |
---|
Day 1 | Place 1 |
Day 2 | Place 2 |
Day 3 | Place 3 |
Day 4 | Place 3 |
- There is a mapping between days and places in itinerary.
- 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
Click to Enlarge