DylanJones1
asked on
C# List.Find and Predicates - How To
I have a list of users that includes name, startdate, and enddate. A user may be listed several times but with diferent start and end dates. I want to create a new list that contains a single entry for each user with that users minimum startdate and maximum enddate. I am using C# and attempting to complete this task using List.Find and Predicates but not having much success. ANy help greatly aprreciated.
TIA
TIA
What have you tried with List.Find and predicates?
Bob
Bob
ASKER
This did what I needed.
List<User> ThisUserList = UserNames.FindAll(delegate (User u) {return ThisUser.UserName == u.UserName; });
List<User> ThisUserList = UserNames.FindAll(delegate
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SELECT User,
(
SELECT Top 1 start_date -- earliest start_date
FROM YourDates
WHERE User = u1.User
ORDER BY start_date
) as start_date,
(
SELECT Top 1 end_date -- latest end_date
FROM YourDates
WHERE User = u1.User
ORDER BY end_date DESC
) as end_date
FROM Users as u1
It can vary a bit depending how you exactly store your data (e.g. User can have UserID PK, not just User, etc.) but that would be the fastest I think.
Good luck,
Yurich