Consider the code below, It is a list of Dictionaries merged to one Dictionary can this be written with linq?
public static Dictionary<string, uint> mergeDictionaries(List<Dictionary<string, uint>> dictlist)
{
Dictionary<string, uint> mergedDict = new Dictionary<string, uint>();
foreach (Dictionary<string, uint> dict in dictlist)
{
foreach (KeyValuePair<string, uint> entry in dict)
{
if (mergedDict.ContainsKey(entry.Key))
{
mergedDict[entry.Key] = mergedDict[entry.Key] + entry.Value;
}
else
{
mergedDict[entry.Key] = entry.Value;
}
}
}
return mergedDict;
}