c# dictionary for loop code example

Example 1: how to do a foreach loop in c# for dictionary

foreach (KeyValuePair<string, int> kvp in myDictionary)
{
	print(kvp)
}

Example 2: iterate through dictionary c#

foreach(var item in myDictionary)
{
  foo(item.Key);
  bar(item.Value);
}

Example 3: c# foreach on a dictionary

foreach(var item in myDictionary)
{
  foo(item.Key);
  bar(item.Value);
}

Example 4: c# dictionary loop key value

foreach(KeyValuePair<string, string> entry in myDictionary)
{
    // do something with entry.Value or entry.Key
}

Example 5: foreach dictionary c#

foreach(KeyValuePair<string, string> entry in myDictionary)
{
    // do something with entry.Value or entry.Key
}