如何从 List
中检索 int
值,该值是其中最大的数字,但仍小于我正在比较的 X
值。
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
我尝试使用 Linq,但到目前为止没有成功。
最佳答案
您可以使用 Where
子句来限制用于获取“最大值”的值:
return myList.Where(x => x < 10).Max();
关于c# - 列表中小于 X 的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30999820/