首页 > 其他 > 详细

Aggregate

时间:2016-10-12 11:34:39      阅读:326      评论:0      收藏:0      [点我收藏+]

https://msdn.microsoft.com/en-us/library/bb549218(v=vs.110).aspx

public static TAccumulate Aggregate<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func);

Parameters

source
Type: System.Collections.Generic.IEnumerable<TSource>

An IEnumerable<T> to aggregate over.

seed
Type: TAccumulate

The initial accumulator value.

func
Type: System.Func<TAccumulate, TSource, TAccumulate>

An accumulator function to be invoked on each element.

举例:

https://www.codewars.com/kata/beginner-reduce-but-grow/train/csharp

对数组中的元素,计算累乘

using System.Linq;

public class Kata
{
    public static int Grow(int[] x)
    {
        return x.Aggregate(1, (current, item) => current * item);
    }
}

 

Aggregate

原文:http://www.cnblogs.com/chucklu/p/5951708.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!