Other Aggregate Functions You Can Apply to Numeric Arrays

Post #147 mentioned using IEnumerable.Average to get the average of an array of numeric values.  The System.Linqnamespace includes several other extension methods for IEnumerable that can be used to aggregate values:
  • Max – Get the maximum value
  • Min – Get the minimum value
  • Sum – Get the sum of all values
1
2
3
4
5
int[] scores = { 89, 98, 72, 100, 83 };
int sum = scores.Sum();        // 442
int min = scores.Min();        // 72
int max = scores.Max();        // 100
double avg = scores.Average();       // 88.4