I need the ability to parse through the values of a Dictionary and
remove certain ones depending on their attribute values. In the example
below, an InvalidOperationException is thrown in the foreach statement
when the first item is removed from the Dictionary.
From looking at Dictionary's methods, I couldn't find anything to
create a copy of the Values before starting the foreach loop. Help?
static void someTest() {
Dictionary<String, Int32storage = new Dictionary<string, Int32>();
for (int i = 0; i < 100; i++) {
String bar = "Test" + i;
Int32 foo = new Int32();
foo = i;
storage.Add(bar, foo);
}
foreach (Int32 tmp in storage.Values) {
if ((tmp % 5) == 0) {
String bar = "Test" + tmp;
storage.Remove(bar);
}
}
}