获取列表<>使用 LINQ 在 c# 中的元素位置

问题描述:

我有一个带数字的列表,我想使用 LINQ 找到最小值(不是值)的位置

I have a List with numbers, and I'd like to find the position of the minimum (not value) using LINQ

示例:

var lst = new List<int>() { 3, 1, 0, 5 };

现在我正在寻找一个返回我的函数

Now I am looking for a function returning me

输出 = 2

因为最小值在列表中的位置 2.

because the minimum is at position 2 in the list.

var list = new List<int> { 3, 1, 0, 5 };
int pos = list.IndexOf(list.Min()); // returns 2