tags:

views:

69

answers:

1

Hi,

I asked a similar question earlier in the week but I don't think my original description of the problem was very coherent, so I am trying again.

I have the following Dictionaries:

public Dictionary<string, List<DateTime>> 1stDict = new Dictionary<string, List<DateTime>>();

Dictionary<string, Dictionary<DateTime, double>> 2ndDict= new Dictionary<string, Dictionary<DateTime, double>>();

I need to create a third Dictionary

Dictionary<string, Dictionary<DateTime, double>> 3rdDict= new Dictionary<string, Dictionary<DateTime, double>>();

Containing Dictionaries with values from 2ndDict where DateTime does not exist in 1stDict.

I've made some attempts using nested foreach statements but having no luck.

Any advice?

Thanks, Brian.

+3  A: 
var thirdDict = secondDict.ToDictionary(
    x => x.Key, 
    x => x.Value.Keys.Except(firstDict[x.Key]).ToDictionary(y => y, y => x.Value[y]));
Kirk Woll
Took me a minute to figure out how this was working, but this is right. Good job figuring this one out..
Jimmy Hoffa
While I agree that a whole different approach is better (as mentioned in comments under the question), this does answer the actual question that was asked. +1
Jason Down
In this example, would I put this within a foreach and iterate through each dictionary with it?
Brian
Jason, can you give an example of different approach?
Brian
Actually Jimmy I just tried this and it seems to work as it is except I am getting more results in each dictionary that I expected. I am looking for only 1 or 2 extra results but am getting anywhere from 40 to 80.
Brian
@Brian, can you give me some sample data? Perhaps I misunderstood some aspect of your data structure.
Kirk Woll
This works perfectly, it was just me being daft at the time. Sorry, I should have come back sooner. Cheers.
Brian