Keith,
you cannot do what you want in this manner.
the foreach statement operates based on the GetEnumerator() reply, and
therefor when you change the content of the arraylist the enumerator is no
longer valid.
try doing it in an other way.
maybe: create a second arraylist for deleted items:
<code>
ArrayList recycleBin = new ArrayList();
foreach (string s in fooList)
{
if (some condition)
{
recycleBin.Add(s);
}
}
foreach (string s in recycleBin)
{
fooList.Remove(s);
}
</code>
HTH
Picho
"Keith O" <ke******@hotmail.com> wrote in message
news:RL********************@rogers.com...
Assume fooList is an ArrayList
foreach(string s in fooList) {
if (some condition) {
fooList.Remove(s);
}
}
I get the following runtime error:
An unhandled exception of type 'System.InvalidOperationException' occurred
in mscorlib.dll
Additional information: Collection was modified; enumeration operation may
not execute.
How can I fix this?
Thanks