获取列表&LT;&GT;使用LINQ在C#中的元素位置 [英] Get List<> element position in c# using LINQ
本文介绍了获取列表&LT;&GT;使用LINQ在C#中的元素位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数字列表,我想使用LINQ to找到最小(不是值)的位置
例如:{3,1,0,5}
输出= 2
解决方案
VAR名单=新名单,LT; INT&GT; {3,1,0,5};
INT POS = list.IndexOf(list.Min()); //返回2
I have a List with numbers, I'd like to find the position of the minimum (not value) using LINQ
eg: {3,1,0,5} output = 2
解决方案
var list = new List<int> { 3, 1, 0, 5 };
int pos = list.IndexOf(list.Min()); // returns 2
这篇关于获取列表&LT;&GT;使用LINQ在C#中的元素位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文