I am looking for a better pattern for working with a list of elements which each need processed and then depending on the outcome are removed from
I found myself in a similar situation where I had to remove every nth element in a given List
.
for (int i = 0, j = 0, n = 3; i < list.Count; i++)
{
if ((j + 1) % n == 0) //Check current iteration is at the nth interval
{
list.RemoveAt(i);
j++; //This extra addition is necessary. Without it j will wrap
//down to zero, which will throw off our index.
}
j++; //This will always advance the j counter
}