C# dictionary

Last modified: June 29, 2021
static void Main(string[] args) { var population = new Dictionary<string, int>() { { "Hong Kong", 700000 }, { "UK", 6600000 } }; //construct a dictionary with few items population.Add("USA", 32800000); //add a new item to dictionary foreach(var p in population) // loop through the dictionary { Console.WriteLine(p.Key + " = " + p.Value); } var item = population.First(f => f.Key == "Hong Kong"); population.Remove(item.Key); //remove an item from dictionary foreach (var p in population) // loop through the dictionary { Console.WriteLine(p.Key + " = " + p.Value); } }