I have this problem. There is a line
string [5] names = { "John", "Sam", "Harry", "Sam", "John" }
I need to find the most common elements in an array. I tried using:
string MostCommon = names.GroupBy(v => v)
.OrderByDescending(g => g.Count())
.First()
.Key;
Unfortunately, it finds only one element, i.e. MostCommon = John, and in this case I need not only John, but also Sam. How could I do this? Maybe LINQ is not needed in this case?
source
share