码迷,mamicode.com
首页 > 其他好文 > 详细

Aggregate

时间:2016-10-12 11:35:34      阅读:129      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!