How do I get the index of the highest value in an array using LINQ?

前端 未结 9 2160
死守一世寂寞
死守一世寂寞 2020-11-27 18:46

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

9条回答
  •  盖世英雄少女心
    2020-11-27 19:01

    var scoreList = score.ToList();
    int topIndex =
        (
          from x
          in score
          orderby x
          select scoreList.IndexOf(x)
        ).Last();
    

    If score wasn't an array this wouldn't be half bad...

提交回复
热议问题