Combine multiple dictionaries into a single dictionary

c#

Solution

var d1 = new Dictionary<string, int>();
var d2 = new Dictionary<string, int>();
var d3 = new Dictionary<string, int>();

var result = d1.Union(d2).Union(d3).ToDictionary (k => k.Key, v => v.Value);

EDIT To ensure no duplicate keys use:

var result = d1.Concat(d2).Concat(d3).GroupBy(d => d.Key)
             .ToDictionary (d => d.Key, d => d.First().Value);

Problem

Possible Duplicate: Merging dictionaries in C# dictionary 1 "a", "1" "b", "2" dictionary 2 "c", "3" "d", "4" dictionary 3 "e", "5" "f", "6" Combined dictionary "a", "1" "b", "2" "c", "3" "d", "4" "e", "5" "f", "6" How do I combine the above 3 dictionaries into a single combined dictionary?

Original source

Related problems