Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含值的字符串数组(duh ...)。
有没有一种简单的方法可以获取出现次数最多的条目?就像是
values[37].getMostOften();
干杯:)
您可以使用GroupBy:
GroupBy
var mostCommonValue = values.GroupBy(v => v) .OrderByDescending(g => g.Count()) .Select(g => g.Key) .FirstOrDefault();