I have a list declared such as:
string[] myList = { "Item One", "Item Two", "Item Three" };
And a dictionary with one element, which value points towards above list:
Dictionary<string, object> myDictionary = new Dictionary<string, object>();
myDictionary.Add("DictionaryItem", myList);
I would like to print the contents of myList
by pointing to the value in the dictionary. I have tried:
foreach (string element in myDictionary["DictionaryItem"])
{
Console.WriteLine(element);
}
Returns syntax error:
foreach statement cannot operate on variables of type object because object does not contain a public definition for GetEnumerator.
How can I print myList
, by pointing to the value of "DictionaryItem"
?