I have code that I want to look like this:
List<Type> Os;
...
foreach (Type o in Os)
if (o.cond)
return; // quiting early is important for my case!
else
Os.Remove(o);
... // other code
This doesn't work because you can't remove from a list inside a foreach over that list:
Is there a common way to solve the problem? I can switch to a different type if needed.
option 2:
List<Type> Os;
...
while (Os.Count != 0)
if (Os[0].cond)
return;
else
Os.RemoveAt(0);
... // other code
Ugly, but it should work.