I\'ve seen a few different ways to iterate over a dictionary in C#. Is there a standard way?
I wrote an extension to loop over a dictionary.
public static class DictionaryExtension
{
public static void ForEach(this Dictionary dictionary, Action action) {
foreach(KeyValuePair keyValue in dictionary) {
action(keyValue.Key, keyValue.Value);
}
}
}
Then you can call
myDictionary.ForEach((x,y) => Console.WriteLine(x + " - " + y));