Aggregate method in C#

CsharpProgrammingServer Side Programming

Use the Aggregate method in C# to perform mathematical operations such as Sum, Min, Max, Average, etc.

Let us see an example to multiply array elements using Aggregate method.

Here is our array −

int[] arr = { 10, 15, 20 };

Now, use Aggregate() method −

arr.Aggregate((x, y) => x * y);

Here is the complete code −

Example

 Live Demo

using System;
using System.Linq;
using System.IO;
public class Demo {
   public static void Main() {
      int[] arr = { 10, 15, 20 };
      // Multiplication
      int res = arr.Aggregate((x, y) => x * y);
      Console.WriteLine(res);
   }
}

Output

3000
raja
Published on 05-Sep-2018 10:56:44
Advertisements