iterate dictionary
Published: 27. October 2011 | Updated: 27. October 2011License: Microsoft Public License (MS-PL)
Categories: Collections
Tags: Basics C# Collections
Import namespace
using System.Collections.Generic;
Code
var dictionary = new Dictionary<int, string>(); dictionary.Add(1, "a"); dictionary.Add(3, "c"); dictionary.Add(6, "c"); dictionary.Add(7, "e"); foreach (KeyValuePair<int, string> pair in dictionary) { Console.WriteLine("{0} > {1}", pair.Key, pair.Value); }Console Output:
1 > a
3 > c
6 > c
7 > e
3 > c
6 > c
7 > e
| Send us feedback about this snippet » |





