Refactoring same loop with different properties
I've been refactoring some of my code, and I ran into a situation I wasn't
sure on how to refactor, I can tell it should be done, just not sure how.
Here it is:
foreach(var item in list)
{
sum = 0;
foreach(var cost in item.data)
{
sum += cost.value;
}
ListObject[count].Sum = sum;
count++
}
Then I have the exact same loop below this one, with the only difference
being the ListObject property. Like ListObject[count].Average = sum;
They are different datasources, so I can't put the Average in the sum.
How can I put this in a method that I could specify what property to use?
No comments:
Post a Comment