Search code examples
c#dictionaryidictionary

Dictionary of dictionaries, how to get value?


I have something like this:

private IDictionary<A, IDictionary<B, C>> data;

and I want to do something like:

IDictionary<B, C> values = new Dictionary<B, C>();
values = Data.Values;

like would I do in java, but this isn't working. I can't figure it out. Thanks for help

error:

Cannot implicitly convert type ICollection> to IDictionary


Solution

  • If you are not sure what will come out, try to use type-inference

    var coll = data.Values;
    

    Then try to acces the Collection using a foreach-loop to access individual dictionaries.

    foreach(var dic in coll){
    //work on Dictionary
    }
    

    See here for a reference.