C# 获取列表中最小值但大于0的有效方法是什么? List List=newlist(){5,4,2,1,0};

C# 获取列表中最小值但大于0的有效方法是什么? List List=newlist(){5,4,2,1,0};,c#,list,linq,C#,List,Linq,list.Min() 我是否应该将其设置为类似于list.Contains(0),然后将其删除?然后,只需在Linq中使用.Min()尝试Where,以过滤掉值,最后使用Min: List <decimal> list = new List<decimal>() {5,4,2,1,0 }; List List=新列表(){ 5, 4, 2, 1, 0 }; // 1 var结果=列表 .Where(item=>item>0)//仅限正数 .Min();//仅限正数中的

list.Min()

我是否应该将其设置为类似于
list.Contains(0)
,然后将其删除?然后,只需在Linq中使用
.Min()
尝试
Where
,以过滤掉值,最后使用
Min

List <decimal> list = new List<decimal>() {5,4,2,1,0 };
List List=新列表(){
5, 4, 2, 1, 0 
};
// 1
var结果=列表
.Where(item=>item>0)//仅限正数
.Min();//仅限正数中的最小值
var result=list.Where(item=>item>0.Min()
 List <decimal> list = new List<decimal>() {
   5, 4, 2, 1, 0 
 };

 // 1
 var result = list
   .Where(item => item > 0) // Only positive numbers
   .Min();                  // Min among positive numbers only