How to loop through dictionary in C#
Back to learning
Created: 12/06/2013
How to loop/iterate through dictionary in C#
How to loop/iterate through dictionary in C#
Just a sample code to loop your dictionary.
---
In this totorial you will see how to use iterate a ditionary in .NET, using C#
it is one of the posible ways
---
private static void LoopMyDictionary()
{
Dictionary<int, string> items = new Dictionary<int, string>();
items.Add(1, "Item 1");
items.Add(2, "Item 2");
foreach (KeyValuePair<int, string> item in items)
{
Console.WriteLine("First property:" + item.Key + ", Second Property: " + item.Value);
}
}
Result:
First property: 1, Second Property: Item 1
First property: 2, Second Property: Item 2
End
---
In this totorial you will see how to use iterate a ditionary in .NET, using C#
it is one of the posible ways
---
private static void LoopMyDictionary()
{
Dictionary<int, string> items = new Dictionary<int, string>();
items.Add(1, "Item 1");
items.Add(2, "Item 2");
foreach (KeyValuePair<int, string> item in items)
{
Console.WriteLine("First property:" + item.Key + ", Second Property: " + item.Value);
}
}
Result:
First property: 1, Second Property: Item 1
First property: 2, Second Property: Item 2
End