I have an array of doubles and I want the index of the highest value. These are the solutions that I\'ve come up with so far but I think that there must be a more elegant so
System.Linq.Enumerable.Select with index and System.Linq.Enumerable.Aggregate would do it in one line
public static int IndexOfMax(this IEnumerable source)
where TSource : IComparable => source.Select((value, idx) => (value, idx))
.Aggregate((aggr, next) => next.value.CompareTo(aggr.value) > 0 ? next : aggr).idx;