Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- int[] array = { 1, 2, 3, 4, 5 };
- int result = array.Aggregate(AddNums);
- // 1 + 2 = 3
- // 3 + 3 = 6
- // 6 + 4 = 10
- // 10 + 5 = 15
- Console.WriteLine(result);
- result = array.Aggregate((a, b) => b * a);
- // 1 * 2 = 2
- // 2 * 3 = 6
- // 6 * 4 = 24
- // 24 * 5 = 120
- Console.WriteLine(result);
- }
- static int AddNums(int a, int b)
- {
- var result = a + b;
- Console.WriteLine($"a:{a} + b:{b} = {result}");
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement