Mode value for IEnumerable
using System.Collections.Generic; using System.Linq; using System; public static class Utilities { public static IEnumerable<double> Mode(this IEnumerable<double> values) { var grouped = values .GroupBy(x => x) .OrderByDescending(x => x.Count()) .Select(x => new { Count = x.Count(), Value = x.Key }); var modes = grouped .Where(x => x.Count == grouped.First().Count) .Select(x => x.Value); return modes; } }