I have a list of work that I'm trying to work on until all work is depleted, but not sure how to handle this. The idea I'm trying to emulate is:
foreach(Work w in _workList) {
res = DoSomethingOnWork(w);
if(res) {
_workList.Remove(w);
}
}
Reason being, when in "DoSomethingForWork(w)" the work may not be what I want to do at that moment, so I'll skip that one and move on to the next. When I'm at the end of the list, I want to go back through the list. Before I go write a collection to handle this, I was curious if there was already something in .NET for handling this situation.
Thanks in advance!
This sort of thing is what the Queue class is for. It holds a collection, and you just dequeue each item to work it. It is a last-in, last-out collection.
If you decide to skip one, you can requeue it for later.
You can also take a look at the Stack class, which is similar but is a last-in, first-out collection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With