how to fetch data from nested Dictionary in c#

c#, dictionary

Solution

Iterate over the outer dictionary, each time iterating members of the nested dictionary, i.e.

(Untested code)

foreach(var key1 in dc.Keys)
{
    Console.WriteLine(key1);
    var value1 = dc[key1];
    foreach(var key2 in value1.Keys)
    {
        Console.WriteLine("    {0}, {1}", key2, value1[key2]);
    }
}

Problem

I need to fetch data from nested Dictionary IN C#. My Dictionary is like this: ``` static Dictionary<string, Dictionary<ulong, string>> allOffset = new Dictionary<string, Dictionary<ulong, string>>(); ``` I need to fetch all keys/values of the full dictionary, represented like so: ``` string->>ulong, string ``` Thanks in advance.

Original source