Question
How do i concat two dictionaries aka the following sample:
Dictionary<int, string> a;
Dictionary<int, string> b;
b.Add(a);
Answer
foreach (KeyValuePair<int,string> pair in b)
{
a.Add(pair.Key, pair.Value);
}
Or if you're using .NET 3.5 you could consider creating a new
dictionary instead, using something like:
var combined = a.Concat(b)
.ToDictionary(pair => pair.Key, pair => pair.Value);