📌  相关文章
📜  unity 获取列表中的最大出现次数 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:50.428000             🧑  作者: Mango

代码示例1
using System.Linq;

# first the max repeated elements
var maxRepeatedItem = prod.GroupBy(x => x)
                          .MaxBy(x => x.Count())
                          .First().Key;

# all the max repeated elements
var grouped = prod.ToLookup(x => x);
var maxRepetitions = grouped.Max(x => x.Count());
var maxRepeatedItems = grouped.Where(x => x.Count() == maxRepetitions)
                              .Select(x => x.Key).ToList();