Aggregate

            int[] agg = new int[] { 10, 2,3,4,5,6,7,8 };
            int[] s = { 1, 2, 3, 4, 45 };
            //  计算和     seed 这里对应 0 ,为x 的初始值
            var ss = agg.Aggregate(0,(x, y) =>
            {
                Console.WriteLine($"x:{x}y:{y}");
                x = y+x;
                return x;  //  每次会将 retuen的值,赋值给x 进行下一次循环
            }
            );

 

posted @ 2020-04-24 16:50  谁说程序猿很猥琐  阅读(216)  评论(0编辑  收藏  举报