Click to See Complete Forum and Search --> : using IEnumerator to removing items


d00_ape
February 28th, 2006, 02:08 AM
I want to remove some items from an ArrayList. Can I do that using a foreach(…)- loop an IEnumerator like this.
foreach(string s in arraylist)
{
if (s == “del”)
{
// Here I want to remove the item from arraylist…
}
}
Any ideas how to solve this without creating a new ArrayList and add items I want to save. Feels like that solution will bee to time consuming…

All tips are welcomed!.

exterminator
February 28th, 2006, 02:27 AM
You cannot do that inside a foreach. You use either a simple for-loop (or while, etc) and use Remove() or RemoveAt() methods.

If you want to use foreach - here is an alternative way of doing but it looks a little too much that can be easily achieved using the way I mentioned above.. here - Isolation - IterIsolate (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp01212002.asp). Hope this helps. Regards.