I have following array:
float[] arr = { 0, 0.1f, 0, 0.1f, 0, 0.2f };
What is the most elegant way to select min value that is bigger than 0 or bigger than some other value?
I've tried using Min()
and Select...From...OrderBy...First()
but no luck until now.
Use the LINQ method Where
to filter out zero values then use the LINQ method Min
to retrieve the lowest value of the resulting collection.
arr.Where(f => f > 0).Min();
You can exclude values using Where
and then apply a Min
:
array.Where(a => a > 1 && a < 10).Min();
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