How to

iterate dictionary

Published: 27. October 2011 | Updated: 27. October 2011
License: Microsoft Public License (MS-PL)
Categories: Collections
Tags: Basics C# Collections
Was this snippet helpful for you? YESYES / NONO

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
Send us feedback about this snippet »



Related Snippets: