What is the best way to iterate over a dictionary?
Explanation
If you want to iterate over a dictionary you can use the following statements:
foreach(var item in myDictionary)
{
foo(item.Key);
bar(item.Value);
}
Or in case if you just want to iterate over the collection of keys, at that time you can use:
foreach(var item in myDictionary.Keys)
{
foo(item);
}
And if you just want to take the values, So use the following:
foreach(var item in myDictionary.Values)
{
foo(item);
}