Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query a Dictionary of Dictionaries?

Please can you advise me on how to query a Dictionary of Dictionaries, and/or a Dictionary of List?

private Dictionary<string, Dictionary<DateTime, double>> masterDict= new Dictionary<string, Dictionary<DateTime, double>>();

Private Dictionary<string, List<DateTime>> masterList= new Dictionary<string, List<DateTime>>();

I know if I do the following, I get a list of the dictionaries contained in masterDict, but I'm not sure how to get at the values of those dictionaries.

 foreach (var kvp in masterDictMethod())
        {
            Console.WriteLine("Key = {0}, Value = {1}",
                kvp.Key, kvp.Value);
        }

Thanks for looking ;)

like image 988
Brian Avatar asked Sep 16 '10 11:09

Brian


Video Answer


1 Answers

In you foreach kvp.Value is the inner dictionary of every masterDict entry i.e. Dictionary<DateTime, double>

So, just foreach also over kvp.Value and you will get the inner values.

e.g.

foreach (var kvp1 in masterDictMethod())
{
   Console.WriteLine("Key = {0}, Inner Dict:", kvp1.Key);
   foreach (var kvp2 in kvp1.Value)
   {
      Console.WriteLine("Date = {0}, Double = {1}", kvp2.Key, kvp2.Value);
   }
}
like image 140
digEmAll Avatar answered Oct 09 '22 23:10

digEmAll