title: How do I get the index of the highest value in an array using LINQ?
body: <p>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 solution. Ideas?</p>
  
  <pre><code>double[] score = new double[] { 12.2, 13.3, 5, 17.2, 2.2, 4.5 };
  int topScoreIndex = score.Select((item, indx) =&gt; new {Item = item, Index = indx}).OrderByDescending(x =&gt; x.Item).Select(x =&gt; x.Index).First();
  
  topScoreIndex = score.Select((item, indx) =&gt; new {Item = item, Index = indx}).OrderBy(x =&gt; x.Item).Select(x =&gt; x.Index).Last();
  
  double maxVal = score.Max();
  topScoreIndex = score.Select((item, indx) =&gt; new {Item = item, Index = indx}).Where(x =&gt; x.Item == maxVal).Select(x =&gt; x.Index).Single();
  </code></pre>