Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualalnite

Posted 26 September 2012 - 05:12 PM

In Java, you have to use the Iterator method. Foreach in Java wouldn't let you remove an item while iterating the list.

After a minute of Google-fu, it seems that there's no other way in C# but to iterate the list using the for-loop. It'd be easier for you if you iterate backwards.

Using Nypyren's code :) :
for (int i=list.Count-1; i >= 0; --i) {
	if (list[i] meets criteria) {
		list.RemoveAt(i);
	}
}

#4alnite

Posted 26 September 2012 - 05:11 PM

In Java, you have to use the Iterator method. Foreach in Java wouldn't let you remove an item while iterating the list.

After a minute of Google-fu, it seems that there's no other way in C# but to iterate the list using the for-loop. It'd be easier for you if you iterate backwards.
for (int i=list.Count-1; i >= 0; --i) {
    if (list[i] meets criteria) {
	    list.RemoveAt(i);
    }
}

#3alnite

Posted 26 September 2012 - 05:11 PM

In Java, you have to use the Iterator method. Foreach in Java wouldn't let you remove an item while iterating the list.

After a minute of Google-fu, it seems that there's no other way in C# but to iterate the list using the for-loop. It'd be easier for you if you iterate backwards.
for (int i=list.Count-1; i >= 0; --i) {
		if (list[i] meets criteria) {
				list.RemoveAt(i);
	    }
}

#2alnite

Posted 26 September 2012 - 05:10 PM

In Java, you have to use the Iterator method. Foreach in Java wouldn't let you remove an item while iterating the list.

After a minute of Google-fu, it seems that there's no other way in C# but to iterate the list using the for-loop. It'd be easier for you if you iterate backwards.
[font=courier new,courier,monospace]for (int i=list.Count-1; i >= 0; --i) {
		if (list[i] meets criteria) {
				list.RemoveAt(i);[/font]
[font=courier new,courier,monospace]		}[/font]
[font=courier new,courier,monospace]}[/font]

#1alnite

Posted 26 September 2012 - 05:10 PM

In Java, you have to use the Iterator method. Foreach in Java wouldn't let you remove an item while iterating the list.

After a minute of Google-fu, it seems that there's no other way in C# but to iterate the list using the for-loop. It'd be easier for you if you iterate backwards.

for (int i=list.Count-1; i >= 0; --i) {
if (list[i] meets criteria) {
list.RemoveAt(i);

}
}

PARTNERS