Get the most common string in an array

I have a string array with values ​​in it (duh ...).

Is there an easy way to get the record that is most found? Sort of

values[37].getMostOften(); 

Greetings :)

+6
source share
1 answer

You can use GroupBy :

 var mostCommonValue = values.GroupBy(v => v) .OrderByDescending(g => g.Count()) .Select(g => g.Key) .FirstOrDefault(); 
+16
source

Source: https://habr.com/ru/post/957546/


All Articles