Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# "deteriorating" list?

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!

like image 425
Mike Avatar asked Nov 29 '22 15:11

Mike


1 Answers

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.

like image 151
Nikki9696 Avatar answered Dec 04 '22 11:12

Nikki9696