How to iterate a C# dictionary

The following snippet shows an easy way to iterate a C# dictionary:

</p><br />
<p>            Dictionary<int, string> dictionary = new Dictionary<int, string>();</p><br />
<p>   <a href="http://www.immobild.de/wp-content/geometry-homework.html" title="literature <a hreflang="en" href="http://www.jolietta.com/" id="hivdrn">julietta casino online</a> review writing">literature review writing</a>          dictionary.Add(1, "Cat");<br /><br />
            dictionary.Add(2, "Dog");<br /><br />
            dictionary.Add(3, "Horse");</p><br />
<p>            foreach (var item in dictionary)<br /><br />
            {<br /><br />
                // do stuff with item<br /><br />
                Console.WriteLine(string.Format("{0} - {1}", item.Key, item.Value));<br /><br />
            }</p><br />
<p>    <a href="http://www.jolietta.com/" hreflang="en" id="yxdwfj">canadian online casinos</a>         // Result:<br /><br />
            // 1 - Cat<br /><br />
            // 2 - Dog<br /><br />
            // 3 - Horse</p><br />
<p>

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.