C#中找到最高数组值和索引 [英] C# find highest array value and index

查看:85
本文介绍了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);

这篇关于C#中找到最高数组值和索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆