0

Say I have a Point:

public class Point
{
    double X, Y;
}

I want to get the index of the element inside List<Point> that satisfy a condition, for example, with the maximum Point.X value inside List<Point>.

How would I do that with a LINQ expression?

John Tan
  • 1,331
  • 1
  • 19
  • 35

1 Answers1

6

You can do using this Select() overlaod which takes index of item as well:

 var result = Points.Select((Point,Index)=> new { Index,Point})
                    .OrderByDescending(x=>x.Point.X).First().Index;
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160