数组获得的最小值大于其他值 [英] Array get min value bigger than other value

查看:53
本文介绍了数组获得的最小值大于其他值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数组:

float[] arr = { 0, 0.1f, 0, 0.1f, 0, 0.2f };

选择大于 0 或大于某些其他值的最小值的最优雅方法是什么?

What is the most elegant way to select min value that is bigger than 0 or bigger than some other value?

我已经尝试过使用Min()Select...From...OrderBy...First(),但是到目前为止还没有运气.

I've tried using Min() and Select...From...OrderBy...First() but no luck until now.

推荐答案

使用LINQ方法

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();

这篇关于数组获得的最小值大于其他值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆