LINQ Aggregate Functions in C#
In this article, I am going to discuss the Linq Aggregate Functions in C# with examples. Please read our previous article before proceeding to this article where we discussed the Reverse Method in C# with some examples. As part of this article, we are going to discuss the following concepts.
- What are Aggregate Functions in Linq?
- When to use Aggregate Functions?
- Types of Aggregate Functions
What are Linq Aggregate Functions?
The Linq aggregate functions are used to group together the values of multiple rows as the input and then return the output as a single value. So, simple word, we can say that the aggregate function in C# is always going to return a single value.
When to use the Aggregate Functions in C#?
Whenever you want to perform some mathematical operations such as Sum, Count, Max, Min, Average, and Aggregate on the numeric property of a collection then you need to use the Linq Aggregate Functions.
What are the Aggregate Methods Provided by Linq?
Following are the aggregate methods provided by Linq to perform mathematical operations on a collection.
- Sum(): This method is used to calculate the total(sum) value of the collection.
- Max(): This method is used to find the largest value in the collection
- Min(): This method is used to find the smallest value in the collection
- Average(): This method is used to calculate the average value of the numeric type of the collection.
- Count(): This method is used to count the number of elements present in the collection.
- Aggregate(): This method is used to Performs a custom aggregation operation on the values of a collection.
In the next article, I will discuss the Linq Sum Aggregate method in details.