解决方案
20
int[] array=new array[]{1,1,1,2,2,2,3,3,4};
var groups=array.GroupBy(x=>x);
var datacounts=groups.Where(x=>x.Count()==groups.Max(y=>y.Count()));
foreach(var datacount in datacounts)
{
Console.WriteLine(datacount.Key);
}
var groups=array.GroupBy(x=>x);
var datacounts=groups.Where(x=>x.Count()==groups.Max(y=>y.Count()));
foreach(var datacount in datacounts)
{
Console.WriteLine(datacount.Key);
}
20
int[] numbers = new int[] { 1, 1, 1, 2, 2, 2,2, 3, 3, 4 }; var results = numbers.GroupBy(x => x).Select(y => new { num = y.Key, count = y.Count() }); var max = results.Max(x => x.count); results = results.Where(r => r.count == max);