辞書のマージ拡張メソッドを作成しようとしています。
私はC#で辞書をマージするソリューション が本当に好きです
キーが終了した場合に辞書アイテムを更新するように上記のソリューションを変更しようとしています。並行辞書は使いたくない。何か案は ?
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**
}
}
}