Get the character and its count which has highest occurrence I have this C# method which get the character and its count which has highest occurrence
    public KeyValuePair&lt;char, int&gt; CountCharMax_Dictionary_LINQ(string s)
    {
        char[] chars = s.ToCharArray();

        var result = chars.GroupBy(x =&gt; x)
            .OrderByDescending(x =&gt; x.Count())
            .ToDictionary(x =&gt; x.Key, x =&gt; x.Count())
            .FirstOrDefault();

        return result;
    }

It works but is there any better or efficient way to get the same result? Is there any difference if I return it as Tuple vs KeyValuePair?
Test data:

Input: 122. Expected Output: 2,1
Input: 122111. Expected Output: 1,4
As per this answer, it would be wiser to use a tuple in this case. I use lowercase &quot;t&quot;uple as I highly recommend the built-in language support for tuples (char, int) over the explicit Tuple&lt;T1, T2&gt; declaration, etc. Few more points:

What should happen in a tie? Which gets returned? If any is acceptable, it's fine as-is. To be more of a determinate function, secondarily order by the character itself.
Don't need to convert it to a character array as a string already is a character array.
Re-order the OrderByDescending and the Select so that Count only has to be called once.
It can be made static since it doesn't access class instance data.
It can be made an extension method if in a static class.
It can be made into an expression-bodied method.
Maybe consider a better name; one that confers what it does rather than how it does it.

All that said, here's my take:
    public static (char, int) MaxCharacterFrequency(this string s) =&gt;
        s.GroupBy(x =&gt; x)
         .Select(x =&gt; (x.Key, x.Count()))
         .OrderByDescending(x =&gt; x.Item2)
         .ThenBy(x =&gt; x.Item1)
         .FirstOrDefault();