Dictionarydictionary = new Dictionary (); dictionary.Add("one", 1); dictionary.Add("two", 2); List > list = dictionary.ToList(); foreach (KeyValuePair item in list) { Console.WriteLine("Key: {0}, Value: {1}", item.Key, item.Value); }
DictionaryThis code example converts the dictionary values into List of integers. The integers can be accessed using foreach loop. The System.Collections namespace is part of the .NET Framework Class Library and is automatically included in C# projects.dictionary = new Dictionary (); dictionary.Add("one", 1); dictionary.Add("two", 2); List list = dictionary.Values.ToList(); foreach (int value in list) { Console.WriteLine("{0}", value); }