If I have a foreach loop, is there any way to check a boolean as well?
I don’t want to check once inside the foreach() and then break for example. I want to foreach over a collection and at the same time evaluate if something is true.
For example, I don’t want to do:
IEnumerable<Job> jobs = currentJobs;
foreach(Job job in jobs)
{
if (found)
break;
}
You could always turn it into a for loop.
You would also need to change jobs from
IEnumerabletoIList. I thinkIListwould serve your purposes better.IEnumerablelazy evaluates the elements just before you need them and doesn’t include the associated collection helper methods.