The SortedDictionary is a collection. We can use the foreach loop to go through all the items and read them using they Key ad Value properties.
foreach
(KeyValuePair<string,
Int16> author in
AuthorList)
{
Console.WriteLine("Key:
{0}, Value: {1}",
author.Key, author.Value);
}
The following code snippet creates a new SortedDictionary and reads all of its items and displays on the console.
public void CreateSortedDictionary()
{
// Create a SortedDictionary with string key and Int16 value pair
SortedDictionary<string, Int16> AuthorList = new SortedDictionary<string, Int16>();
AuthorList.Add("Mahesh Chand", 35);
AuthorList.Add("Mike Gold", 25);

Join the conversation! Your thoughts help the community grow.