Link to home
Start Free TrialLog in
Avatar of diablo089
diablo089Flag for United States of America

asked on

Find Max of Values using LINQ and Subquery

I have a List of doubles, sorted ascending. How can I use LINQ to query the list for the maximum double in the list that is less than a random value I choose?
ASKER CERTIFIED SOLUTION
Avatar of Craig Wagner
Craig Wagner
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
You forgot the Max operator...
Avatar of diablo089

ASKER

Can you guys explain a little as to how this works? Thanks.
What kind of explanation do you need?  Do you need to know how to compose a LINQ statement?  Do you need to know what the operator extension methods do?
The statement I posted doesn't need a Max operator, it sorts the items descending and then grabs the first one (i.e. the max). But now that you mention it, this would also work.

double maxDouble = doubleList.Where( d => d > someRandomValue ).Max();
All of the above.
SOLUTION
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
Thanks Craig. I appreciate your effort.
The order of operations, says that you sort after the Where clause...