so basically I have a dictionary where I have a key, and then the value is a list that contains strings.. so for example..
{"key1", list1}
list1 = [Value 1 Value2, Value3]
And I have multiple keys and therefore values that have lists. I want to display it so that it shows
Key1: Value1
Key1: Value2
Key1: Value3
So I want to be able to display the Key and also the value. But I am unsure of how to do that.
foreach (var value in FoodCategory_Item.Values)
{
foreach(var item in value)
{
Console.WriteLine("Value of the Dictionary Item is: {0}", item);
}
}
That's what I have so far, which is to iterate over the values, which I know how to do, but I am not sure how to get the key values in there as well, because it will iterate over all the values first, and then iterate through the key items..
This should work:
Dictionary
implementsIEnumerable<KeyValuePair<TKey, TValue>>
, so you can iterate over it directly.