diablo089
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You forgot the Max operator...
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();
double maxDouble = doubleList.Where( d => d > someRandomValue ).Max();
ASKER
All of the above.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Craig. I appreciate your effort.
The order of operations, says that you sort after the Where clause...