I have two dictionaries with the same structure:
Dictionary foo = new Dictionary()
{
{\"Table\", 5 },
{\"Chair
What about something like this?
var fooBar = foo.Keys
.Union(bar.Keys)
.Select(
key => {
int fval = 0, bval = 0;
foo.TryGetValue(key, out fval);
bar.TryGetValue(key, out bval);
return new KeyValuePair(key, fval + bval);
}
)
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
At least it's (kind of?) neat.