Best way to iterate over a Dictionary
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
class Program { static void Main(string[] args) { Dictionary<string, int> dic = new Dictionary<string, int>(); dic.Add("Red", 1); dic.Add("Green", 2); dic.Add("Blue", 5); dic.Add("Yellow", 20); foreach (KeyValuePair<string, int> entry in dic) { Console.WriteLine("Key:{0} Value:{1}",entry.Key, entry.Value); } Console.ReadLine(); } } |
Output:

Add comment