What is the diffrence between the two functions: Sum / Aggregate?
4 Answers
You can essentially think of Sum as one particular type of Aggregate, but there are many other types.
Some examples of Aggregate might be to multiply every single value, or to add strings rather than numbers.
The reason that Sum exists in addition to Aggregate is simply that Sum is one of the more common types of Aggregate functions, so it was worthwhile to add an additional function for that case.
Comments
Sum method in Linq Operates only on numerical data type (int,float etc) where as Aggregate method can be operated on numerical data type as well as string data type.
string[] countries = { "Brazil", "Argentina", "England", "Spain"};
string result = countries.Aggregate((a, b) => a + ", " + b);
//result="Brazil,Argentina,England"
int[] Numbers = { 2, 3, 4 };
int aggregate= Numbers.Aggregate((a, b) => a * b);
//aggregate=24