You can subvert the read-only characteristics of the foreach construct using
this code
foreach(string s in new System.Collection.ArrayList(fooList)) { //this
opening brace should be on
//the next line by the way
if (some condition) {
fooList.Remove(s);
}
}
Is it a recommended approach? I sincerely doubt it but that's a question for
another thread?
--
Regards,
Alvin Bruney [Microsoft MVP ASP.NET]
[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @
http://www.lulu.com/owc
----------------------------------------------------------
"Keith O" <(E-Mail Removed)> wrote in message
news:RLKdneKWvd662I3fRVn-(E-Mail Removed)...
> 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
>
>