Reputation: 5818
My VS2010 using ReSharper which prompts to converts foreach
to LINQ. It converts from
foreach (var item in quotePrice.ExtraServiceBreakdown)
{
hazmatRate = (quoteRequest.IsHazMat && item.Id == VitranHazmatCode) ?
item.Cost : hazmatRate;
}
to
hazmatRate = quotePrice.ExtraServiceBreakdown.Aggregate(
hazmatRate, (current, item) =>
(quoteRequest.IsHazMat && item.Id == VitranHazmatCode) ?
item.Cost : current);
I have two questions here,
current
meant? Is that points to the variable hazmatRate
?Aggregate
actually does? Upvotes: 1
Views: 129
Reputation: 2629
And i think you will need to do as stated in the comment by Tim:
hazmatRate += (quoteRequest.IsHazMat && item.Id == VitranHazmatCode) ? item.Cost : hazmatRate;
But in this case i'd change 'hazmatRate' by a base rate declared before your function. Otherwise you would be increasing your value with the value it contained before making it grow exponentially
Upvotes: 1