How to get index using LINQ? [duplicate]

myCars.Select((v, i) => new {car = v, index = i}).First(myCondition).index;

or the slightly shorter

myCars.Select((car, index) => new {car, index}).First(myCondition).index;

or the slightly shorter shorter

myCars.Select((car, index) => (car, index)).First(myCondition).index;

Leave a Comment