How to retrieve int
value from List
that is biggest number on it but still smaller than X
value to which i am comparing.
Value = 10
Example one: List = {1,4,6,8}; => number 8 biggest on list and smaller than 10
Example two: List = {1,15,17,20}; => number 1 biggest on list and smaller than 10
I was trying using Linq but no success so far.
You can just restrict the values you use to get the "Max" by using a Where
clause:
return myList.Where(x => x < 10).Max();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With