Friday, 15 April 2011

c# - Automatic conversion with LINQ -



c# - Automatic conversion with LINQ -

my vs2010 using resharper prompts converts foreach linq. 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 2 questions here,

what current meant? points variable hazmatrate? what aggregate does?

current indeed point hazmat linq aggregate algorithm explained

and think need stated in comment tim:

hazmatrate += (quoterequest.ishazmat && item.id == vitranhazmatcode) ? item.cost : hazmatrate;

but in case i'd alter 'hazmatrate' base of operations rate declared before function. otherwise increasing value value contained before making grow exponentially

c# linq

No comments:

Post a Comment