I have a collection List<CustomClass>
that I am trying to find a way to return a field corresponding to another field that occurs the most times. I asked a similar question in the past, but I'm not sure how to extend the logic to a user class. For instance.
My CustomClass
has three public properties:
Title
Mid
Eid
And a is List<CustomClass> MatchedFeatures = List<CustomClass>();
filled in a loop.
I need to perform a Linq operation in order to return the Mid
class with the largest number of identical ones encountered Eid
. So we count the same columns Eid
.
I tried using
var TopResult = MatchedFeatures.GroupBy(MatchedFeature => MatchedFeature).OrderByDescending(group => group.Count()).FirstOrDefault();
But he does not return what I am looking for.
Can anyone see where I'm wrong? I am using c #
, , , . , ...?
LINQ #
,