hello - 7 months ago 55

C# Question

I'm trying to find the

`index`

`List<>`

`max`

`max`

`LINQ`

`var result = link.Select(x => Math.Abs(x.Prop1 - x.Prop2)).Max();`

How can I get the index ?

Answer

```
var result =
link.Select((x, i) => new { value = Math.Abs(x.Prop1 - x.Prop2), index = i })
.OrderByDescending(x=>x.value)
.FirstOrDefault();
var indexValue = result?.index;
var maxValue = result?.value;
```

Here this is working.

Source (Stackoverflow)