#150 – 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.Linq namespace 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
            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
Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: