C # Linq question GROUP BY?

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 CustomClasshas 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 Midclass 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 #

,

+3
2

, Eid , GroupBy(MatchedFeature => MatchedFeature.Eid).

.Eid, , , , Eid.

+6

MatchedFeature => MatchedFeature.Eid MatchedFeature => MatchedFeature, hense, , .

0

Source: https://habr.com/ru/post/1795616/


All Articles