I have a foreach method like this one:
public void Initialize(ClassB fixed)
{
foreach (ClassA item in itemCollection)
{
this.InitializeStock(fixed, item);
}
}
I would like to use a Parallel.ForEach with this one but not sure on how to do it. I cannot set the fixed parameter as a class attribute as the Initialize method is already called from another Parallel.ForEach.
Thanks in advance.
It’s not clear what the problem is. This should be fine:
The
fixedvariable will be captured by the lambda expression so that it can be used when callingInitializeStock.EDIT: If you really don’t want lambda expressions:
… but really, which would you rather read?