LeetCode: Top K Frequent Elements C#
I think that in terms of performance you'd be hard pressed to do better than a LINQ query.  Not only fast but very compact and relatively easy to understand.  It could look something like this:

public IList&lt;int&gt; TopKFrequent(int[] nums, int k) {
    var answer = (from int n in nums
                  group n by n into g
                  orderby g.Count() descending 
                  select g.Key).Take((k)).ToList();
    return answer;
}


For those that prefer method syntax here's the equivalent:

public IList&lt;int&gt; TopKFrequent(int[] nums, int k) {
    var answer = nums.GroupBy(n =&gt; n).OrderByDescending(g =&gt; g.Count()).Take(k).Select(g =&gt; g.Key).ToList();
    return answer;
}