[Fork] [Fork] Hash Table in C#

CSharp · Console

/Program.cs

using System;
using System.Collections;

public class Program
{
	public static void Main()
	{
		//creating a Hashtable using collection-initializer syntax
		Hashtable cities = new Hashtable()
		{
			{"India", "Mumbai, New Delhi, Pune"},
			{"UK", "London, Manchester, Birmingham"}, 
			{"USA", "Chicago, New York, Washington"}
		};
		
		string citiesOfUK = (string)cities["UK"]; //cast to string
		string citiesOfUSA = (string)cities["USA"]; //cast to string
		Console.WriteLine("City of UK :"  +citiesOfUK);
		Console.WriteLine("City of USA :" +citiesOfUSA);
		cities["UK"] = "Liverpool, Bristol"; // update value of UK key
		cities["USA"] = "Los Angeles, Boston"; // update value of USA key
		if (!cities.ContainsKey("France")) //Add value in new Key "France"
		{
			cities["France"] = "Paris";
		}

		Console.WriteLine();
		Console.WriteLine("=============================");
		foreach (DictionaryEntry de in cities)
			Console.WriteLine("Key: {0}, Value: {1}", de.Key, de.Value);
	}
}
;