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.
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 APe -
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!. _____________________________ ...and justice for all APed00_ape wrote:
I want to remove some items from an ArrayList.
Check out ArrayList.Remove(). I think that will do the job for you. Cheers, Vikram.
"Don't judge me You could be me in another life In another set of circumstances" - "Tomorrow we'll see", Sting.
-
d00_ape wrote:
I want to remove some items from an ArrayList.
Check out ArrayList.Remove(). I think that will do the job for you. Cheers, Vikram.
"Don't judge me You could be me in another life In another set of circumstances" - "Tomorrow we'll see", Sting.
Yeah!! something like this:
int iIndex = 0; while( iIndex < arrayList.Count) { if( //you need to remove this item) { arrayList.RemoveAt( iIndex); } else { iIndex++; } }
_____________________________ ...and justice for all APe -
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!. _____________________________ ...and justice for all APeHi APe, Whenever you need to remove any item/s from an ArrayList, and that too by looping then you always need to traverse the ArrayList in reverse order. This requirement cannot be achieved using an foreach statement. So, I think you would need to use the 'FOR' loop, as follows:
for (int i = testList.Count-1; i >= 0; i--) { if(CONDITION is TRUE) { testList.RemoveAt(i); } }
Regards, vinSharp There are two types of fools in this world: One who give advice and the others who do not take it...:laugh: