A newbie with C# and LINQ. I have an array which is essentially a counted sequence.
{1,3,5,2,7,2}
I am trying to write a query that returns list of indices with highest values in descending order:
4,2,1,3,5,0
I can get the maximum index with this query below, but I can't seem to work out how to get the next indexes in sequence with a single query.
int index = array.ToList().IndexOf(array.Max());
This works:
var list = new [] {1,3,5,2,7,2};
var indices =
list
.Select((n, i) => new { n, i })
.OrderByDescending(x => x.n)
.Select(x => x.i)
.ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With