I am trying to use LINQ
to return the an element which occurs maximum number of times AND the number of times it occurs.
For example:
I have an array of strings:
string[] words = { "cherry", "apple", "blueberry", "cherry", "cherry", "blueberry" };
//...
Some LINQ statement here
//...
In this array, the query would return cherry
as the maximum occurred element, and 3
as the number of times it occurred. I would also be willing to split them into two queries if that is necessary (i.e., first query to get the cherry
, and second to return the count of 3
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…