Alternative for two sequentially executed loops with identical ranges For the moment I'm executing my code as follows:

foreach (int data in dataList)
{
    PreProcess(data);
}
foreach (int data in dataList)
{
    Process(data);
}


First I have to loop over some data (from a list) and to do some pre-processing after which then I do have to loop again over the same data list and do some processing, but those loops have to be run one after another, and cannot be merged as follows...

foreach (int data in dataList)
{
    PreProcess(data);
    Process(data); // Cannot be run in the same loop with PreProcess(data);
}


...because PreProcess(data) and Process(data) are logging a lot of information which could be interlaced in case both are looping together.



The only alternative I've found will be using Linq, but still has the same duplicate ForEach:

dataList.ForEach(data =&gt; { PreProcess(data); });
dataList.ForEach(data =&gt; { Process(data); });




Is there any way to rewrite this in order to remove the redundancy for two loops with same range, but still looping sequentially first over PreProcess(data) and Process(data) afterwards?
You could also define something like

private void MyLoop&lt;T&gt;(Action&lt;T&gt; action, IEnumerable&lt;T&gt; dataList) 
{
    foreach (var data in dataList)
    {
        action(data);
    }
}


and use it

MyLoop(Process, dataList);


or using Action

Action&lt;Action&lt;int&gt;&gt; myLoop= action =&gt;
{
    foreach (var data in dataList)
    {
        action(data);
    }
};


and use it like this

myLoop(Process);