What is the best way to iterate over a dictionary?

Jake Stewart picture Jake Stewart · Sep 26, 2008 · Viewed 1.7M times · Source

I've seen a few different ways to iterate over a dictionary in C#. Is there a standard way?

Answer

Pablo Fernandez picture Pablo Fernandez · Sep 26, 2008
foreach(KeyValuePair<string, string> entry in myDictionary)
{
    // do something with entry.Value or entry.Key
}