C#中找到最高数组值和索引

问题描述:

所以我有一个排序的数值数组 INT [] anArray = {1,5,2,7}; ,我需要得到双方的价值和指数数组中的最大价值这将是7和3,我会怎么做呢?

So I have an unsorted numeric array int[] anArray = { 1, 5, 2, 7 }; and I need to get both the value and the index of the largest value in the array which would be 7 and 3, how would I do this?

这是不是最富有魅力的方式,但工作。

This is not the most glamorous way but works.

 int maxValue = anArray.Max();
 int maxIndex = anArray.ToList().IndexOf(maxValue);