Dictionary index
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
class Program { static void Main(string[] args) { //initialize a dictionary with keys and values. Dictionary<int, string> birds = new Dictionary<int, string>() { {1,"Snowy Sheathbill"}, {2,"Magellanic Plover"}, {3,"Black Oystercatcher"}, {4,"Eurasian Oystercatcher"}, {5,"Crab Plover"} }; Console.WriteLine("dictionary keys and values.........."); foreach (KeyValuePair<int, string> pair in birds) { Console.WriteLine(pair.Key + " ........ " + pair.Value); } Console.WriteLine("\ndictionary elements with index.........."); for (int i = 0; i < birds.Count; i++) { Console.WriteLine("index:{0} key:{1} value:{2} ", i, birds.ElementAt(i).Key, birds.ElementAt(i).Value); } Console.ReadLine(); } } |
Output: