ASP.NET C# - Get Average After Removing Two Highest and Lowest Numbers

Using ASP.NET / C#, how can I get the average of an array of numbers, after removing the two highest and the two lowest numbers?
double[] HourSpreads = new double[] { 23.1, 45.4, 11.42, 63.74, 77.2, 98.5, 91.2, 9.423};

Open in new window

LVL 10
Who is Participating?
using System.Linq;

double average = HourSpreads.OrderBy(p => p).Skip(2).Take(HourSpreads.Count() - 4).Average();

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.