本文翻译自:How to get index using LINQ? [duplicate]
This question already has an answer here: 这个问题已经在这里有了答案:
Given a datasource like that: 给定这样的数据源:
var c = new Car[]
{
new Car{ Color="Blue", Price=28000},
new Car{ Color="Red", Price=54000},
new Car{ Color="Pink", Price=9999},
// ..
};
How can I find the index of the first car satisfying a certain condition with LINQ? 如何使用LINQ找到满足特定条件的第一辆汽车的索引 ?
EDIT: 编辑:
I could think of something like this but it looks horrible: 我可以想到这样的东西