Key ExamplesΒΆ

A property that isolates the keys of a dictionary.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
Dictionary<string, int> moons = new Dictionary<string, int>();
   moons.Add("Mercury", 0);
   moons.Add("Venus", 0);
   moons.Add("Earth", 1);
   moons.Add("Mars", 2);
   moons.Add("Jupiter", 79);
   moons.Add("Saturn", 82);
   moons.Add("Uranus", 27);
   moons.Add("Neptune", 14);

foreach(KeyValuePair<string,int> moon in moons)
{
   Console.WriteLine(moon.Key);
}

Output

Mercury
Venus
Earth
Mars
Jupiter
Saturn
Uranus
Neptune