I have a string array with values in it (duh...).
Is there an easy way of getting the entry which occurs the most? Something like
values[37].getMostOften();
Cheers :)
You can use GroupBy
:
var mostCommonValue = values.GroupBy(v => v)
.OrderByDescending(g => g.Count())
.Select(g => g.Key)
.FirstOrDefault();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.