|
-
February 28th, 2006, 03:08 AM
#1
using IEnumerator to removing items
I want to remove some items from an ArrayList. Can I do that using a foreach(…)- loop an IEnumerator like this.
Code:
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!.
...and justice for all
-
February 28th, 2006, 03:27 AM
#2
Re: using IEnumerator to removing items
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. Hope this helps. Regards.
Last edited by exterminator; February 28th, 2006 at 03:29 AM.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|