Programming Language: C# (CSharp)

Class/Type: System

Method/Function: Aggregate

Examples at hotexamples.com: 30

The System Aggregate is a package library in C# that provides powerful functions for working with collections of data. It is used to perform various calculations on a collection of values, such as calculating the sum, average, minimum or maximum value of a collection.

Below are some examples of how to use System Aggregate in C#:

1. Calculate the sum of a collection of numbers:

2. Calculate the average of a collection of numbers:

3. Find the maximum value in a collection of numbers:

Below are some examples of how to use System Aggregate in C#:

1. Calculate the sum of a collection of numbers:

int[] numbers = { 1, 2, 3, 4, 5 }; int sum = numbers.Aggregate((a, b) => a + b); // Output: 15

2. Calculate the average of a collection of numbers:

double[] numbers = { 1, 2, 3, 4, 5 }; double average = numbers.Aggregate((a, b) => a + b) / numbers.Length; // Output: 3

3. Find the maximum value in a collection of numbers:

int[] numbers = { 1, 2, 3, 4, 5 }; int max = numbers.Aggregate((a, b) => a > b ? a : b); // Output: 5These examples demonstrate how to use System Aggregate to perform different calculations on collections of data. The System Aggregate package library is part of the .NET framework and is included in the System.Linq namespace.

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related in langs

Frequently Used Methods

Related