public static Tres MostCommon<Tsrc, Tres>(this IEnumerable<Tsrc> source, Func<Tsrc, Tres> transform)
{
return source.GroupBy(s => transform(s)).OrderByDescending(g => g.Count()).First().Key;
}
And in your example with integral types you can call it as:
List<int> a = new List<int>{ 1,1,2,2,3,4,5 };
int mostCommon = a.MostCommon(x => x);