I have a dictionary:
Dictionary<string, long> Reps = new Dictionary<string, long>();
and I want to update values ββduring iteration over all elements, for example:
foreach (string key in Reps.keys) { Reps[key] = 0; }
he gives me an error saying:
"Collection was modified; enumeration operation may not execute"
can someone tell me why it gives me this error, because I have another function that adds a value, and it is called when the button is clicked:
public static void Increment(string RepId, int amount) { long _value = Convert.ToInt64(Reps[RepId]); _value = _value + amount; Reps[RepId] = _value; }
and this function works fine. so what's the problem of updating all values? And what is the solution for this?
source share