说我有一个Point:
public class Point
{
double X, Y;
}
Run Code Online (Sandbox Code Playgroud)
我想得到List<Point>满足条件的元素索引,例如,Point.X里面有最大值List<Point>.
我如何使用LINQ表达式执行此操作?
你可以使用这个Select()带有项目索引的重叠:
var result = Points.Select((Point,Index)=> new { Index,Point})
.OrderByDescending(x=>x.Point.X).First().Index;
Run Code Online (Sandbox Code Playgroud)