获取满足条件的List中元素的索引

Joh*_*Tan 0 c# linq

说我有一个Point:

public class Point
{
    double X, Y;
}
Run Code Online (Sandbox Code Playgroud)

我想得到List<Point>满足条件的元素索引,例如,Point.X里面有最大值List<Point>.

我如何使用LINQ表达式执行此操作?

Ehs*_*jad 6

你可以使用这个Select()带有项目索引的重叠:

 var result = Points.Select((Point,Index)=> new { Index,Point})
                    .OrderByDescending(x=>x.Point.X).First().Index;
Run Code Online (Sandbox Code Playgroud)