Search code examples
c#listdictionarycollectionssorteddictionary

Display elements from nested SortedDictionary


I have list:

ProjectTaskList = new SortedDictionary<string, SortedDictionary<string, string>>();

I try to display all the elements from the list:

foreach (var itemList in ProjectTaskList)
{
 Console.WriteLine("Value: " + itemList.Value + ", Key: " + itemList.Key);                
}

How can I display element from nested SortedDictionary<string, string> ?


Solution

  • To display the key and then all the key/value pair for each itemList:

    foreach (var itemList in ProjectTaskList)
    {
        Console.WriteLine($"Key: {itemList.Key}");
    
        foreach (var entry in itemList.Value)
        {
            Console.WriteLine($"Value: {entry.Value}, Key: {entry.Key}");
        }
    }