I am trying to write an merge extension methods for my dictionary.
I really like the solution Merging dictionaries in C#
I am trying to modify the above solution to update the dictionary item if key exits. I do not want to use Concurrent dictionary. Any ideas ?
public static void Merge<TKey, TValue>(this IDictionary<TKey, TValue> first, IDictionary<TKey, TValue> second)
{
if (second == null) return;
if (first == null) first = new Dictionary<TKey, TValue>();
foreach (var item in second)
{
if (!first.ContainsKey(item.Key))
{
first.Add(item.Key, item.Value);
}
else
{
**//I Need to perform following update . Please Help
//first[item.Key] = first[item.key] + item.Value**
}
}
}