我有一本字典:
Dictionary<string,long> Reps = new Dictionary<string,long>();
我想在迭代所有项目时更新值,如下所示:
foreach (string key in Reps.keys) { Reps[key] = 0; }
它给我一个错误说:
"Collection was modified; enumeration operation may not execute"
任何人都可以告诉我为什么它给我这个错误,因为我还有一个函数添加了值,并在单击按钮时调用它:
public static void Increment(string RepId,int amount) { long _value = Convert.ToInt64(Reps[RepId]); _value = _value + amount; Reps[RepId] = _value; }