Where is the “Fold” LINQ Extension Method?

a 夏天 提交于 2019-12-03 22:01:20

You will want to use the Aggregate extension method:

double product = doubles.Aggregate(1.0, (prod, next) => prod * next);

See MSDN for more information. It lets you specify a seed and then an expression to calculate successive values.

Fold (aka Reduce) is the standard term from functional programming. For whatever reason, it got named Aggregate in LINQ.

double product = doubles.Aggregate(1.0, (runningProduct, nextFactor) => runningProduct* nextFactor);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!