27
1
using System;
2
using System.Collections.Generic;
3
4
public class Program
5
{
6
public static void Main()
7
{
8
IDictionary<int, string> numberNames = new Dictionary<int, string>();
9
numberNames.Add(1,"One"); //adding key/value using the Add() method
10
numberNames.Add(3,"Three");
11
numberNames.Add(2,"Two");
12
13
foreach(KeyValuePair<int, string> kvp in numberNames)
14
Console.WriteLine("Key: {0}, Value: {1}", kvp.Key, kvp.Value);
15
16
//creating a dictionary using collection-initializer syntax
17
var cities = new Dictionary<string, string>(){
18
{"UK","London, Manchester, Birmingham"},
19
{"USA","Chicago, New York, Washington"},
20
{"India","Mumbai, New Delhi, Pune"}
21
};
22
23
foreach(var kvp in cities)
24
Console.WriteLine("Key: {0}, Value: {1}", kvp.Key, kvp.Value);
25
26
}
27
}
Cached Result
CoOrds 1: x = 10, y = 20