how to do a foreach loop in c# for dictionary
foreach (KeyValuePair<string, int> kvp in myDictionary)
{
print(kvp)
}
how to do a foreach loop in c# for dictionary
foreach (KeyValuePair<string, int> kvp in myDictionary)
{
print(kvp)
}
iterate through dictionary c#
foreach(var item in myDictionary)
{
foo(item.Key);
bar(item.Value);
}
how to print dictionary in c# with for loop
using System;
using System.Linq;
using System.Collections.Generic;
public class Example
{
public static void PrintDict<K,V>(Dictionary<K,V> dict)
{
for (int i = 0; i < dict.Count; i++)
{
KeyValuePair<K, V> entry = dict.ElementAt(i);
Console.WriteLine(entry.Key + " : " + entry.Value);
}
}
public static void Main()
{
Dictionary<string, string> dict = new Dictionary<string, string>
{
{ "key1", "value1" },
{ "key2", "value2" }
};
PrintDict(dict);
}
}
/*
Output:
key1 : value1
key2 : value2
*/
c# foreach on a dictionary
foreach(var item in myDictionary)
{
foo(item.Key);
bar(item.Value);
}
foreach dictionary c#
foreach(KeyValuePair<string, string> entry in myDictionary)
{
// do something with entry.Value or entry.Key
}
c# dictionary loop key value
foreach(KeyValuePair<string, string> entry in myDictionary)
{
// do something with entry.Value or entry.Key
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us