user3916429 user3916429 - 3 months ago 11
C# Question

Get all Keys from a MultiDictionary

Im looking for a way to get all FIRST level Keys of a multiDictionary and im totaly unable to get them (its for debugging purpose)

i declared the dictionary like this :

private Dictionary<string, Dictionary<string, Packet>> PacketsStore = new Dictionary<string, Dictionary<string, Packet>>();


So how can i print out a list of all the base keys?

how could i then print out the second level keys incase i need it too later...

thanks in advance!

Answer
foreach(KeyValuePair<string, Dictionary<string, Packet>> entry in PacketsStore)
{
    string key = entry.Key; // first level
    foreach(KeyValuePair<string, Packet> entryInner in entry.Value)
    {
       string keyInner = entryInner.Key // second level
    }
}

I have taken keys into variables you can take the same into some collection. Purpose was to get keys :)

Comments