I think this would fall under a "misuse of ForEach" category. You are never incrementing i
first of all (that I can see) which is your main problem. The major disadvantage to .ToList().ForEach()
is it's poor readability.
I think you would be better off just using loops first until you are getting the results you want, then if you really must go ahead and convert to LINQ.
var pCol = new ReportParameterCollection();
for (int i = 0; i < parameters.Length; i++)
{
pCol.Add(new ReportParameter(ReportParameters[i].Name, parameters[i]);
}
Really not sure why you are checking the length of ReportParameters
and parameters
. The code is fairly unclear and your intent is not written out that I can see. But I would "un-optimize" this code so that it is easier to step through in the debugger then go for optimization later when your method is working properly.