I'm using the answer from this link Linq join two dictionaries using a common key
to produce the result that I want. Unfortunately, I'm not sure how to convert the result back into a dictionary object, since the result is some type of System.Linq.Enumerable+WhereSelectEnumerableIterator and I'm not sure what to do with that.
Okay, specifics. Suppose I have the following:
[Flags]
enum People { Adam = 0x1, Barry = 0x2, Chris = 0x4, David = 0x8,
Eric = 0x10, Frank = 0x20, George = 0x40, Harold = 0x80 };
Dictionary<string, People> EUInterest = new Dictionary<string, People>() {
{ "athletes", People.Adam | People.Barry },
{ "artists", People.Frank | People.Harold } };
Dictionary<string, People> USInterest = new Dictionary<string, People>() {
{ "athletes", People.Chris | People.Harold },
{ "artists", People.Eric } };
var result = from interest in EUInterest.Keys
where USInterest.ContainsKey(interest)
let v1 = EUInterest[interest]
let v2 = USInterest[interest]
select new Dictionary<string, People>() { {interest, v1 | v2 } };
When I look at result in the debugger, I see the "Results View" has almost what I want it to have. It looks like it creates two dictionaries with a single Key. Which, now that I look closely at the query, that's exactly what it does.
Here is what I want the result to be:
Dictionary<string, People> result = new Dictionary<string, People>() {
{ "athletes", People.Adam | People.Barry | People.Chris | People.Harold },
{ "artists", People.Frank | People.Harold | People.Eric } };
Even if I'm able to get the var result
how I want it from the select query, I'm not sure how to access that data, because it won't be a Dictionary object. (I can easily use the wonderful merge extension that Andrew Orsich provided here: Merging dictionaries in C#)