Link to home
Start Free TrialLog in
Avatar of wegee2
wegee2

asked on

Distinct List Items - Sort of

Given this dataset in a List<CustomItem>, where CustomItem = string Name, int Index, int FID, and a few other random fields:

Name	Index	FID	Misc
user1	100	3	random
user1	200	3	random
user1	100	4	random
user1	200	4	random
user1	300	4	random
user20	100	2	random
user20	200	2	random
user20	300	2	random
user20	100	4	random
user20	200	4	random
user20	300	4	random

Open in new window

I want to extract objects that have the highest Index value, given where Name and FID are equal.

From the above set, I would want these rows:

Name	Index	FID	Misc
user1	200	3	random
user1	300	4	random
user20	300	2	random
user20	300	4	random

Open in new window

I'm using a non-LINQ method now whereby I start with the first record and iterate through the list doing a manual comparison of line by line to see if I should add it to my resultset.

The LINQ .Distinct doesn't seem to be what I want.  I think it's going to be some combinations of group by's and max and let's, but I'm kinda swimming in unfamiliar territory with this one.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wegee2
wegee2

ASKER

Fernando,

Spot on.  Not only did that work, the results are lightning fast over a large list.  

Thank you.
Not a problem, glad to be of help.  ;=)