I have a foreach loop like the following:
that I run with my dictionary ddd. I intend to calculate the sum for each header in a table, where the first int is the day of the month...
Now, when I run this loop I obtain a error saying that 'Collection was modified; enumeration operation may not execute.'.
But I don't alter the dictionary, at least consciously. When I use l.Value[k] ?? "0,00" gives also an error.
It seems that the use of .ContainsKey creates a key in the dictionary...
How may I do this?
C#:
private Dictionary<string,double> SumDictDaysExpDetail(Dictionary<int,Dictionary<string,string>> ddd)
{
Dictionary<string, double> dsum = appDataContext.MyFields.ToDictionary(l => l.drName, l => 0.0);
foreach (string k in dsum.Keys)
{
List<string> ls = ddd.Select(l => l.Value.ContainsKey(k) ? l.Value[k] : "0,00").ToList();
dsum[k] = ls.Sum(l => Convert.ToDouble(l));
}
return dsum;
}
that I run with my dictionary ddd. I intend to calculate the sum for each header in a table, where the first int is the day of the month...
Now, when I run this loop I obtain a error saying that 'Collection was modified; enumeration operation may not execute.'.
But I don't alter the dictionary, at least consciously. When I use l.Value[k] ?? "0,00" gives also an error.
It seems that the use of .ContainsKey creates a key in the dictionary...
How may I do this?