有一个数组check[11],怎样找出最大数的索引,但又不改变check[11]中的值顺序

解决方案 »

  1.   

    用 linq
    int maxValue = check.Max();
    这是找到最大的值
    再用 indexOf 去找索引
      

  2.   

    int index = -1;
    for (int i = 0, max = int.MinValue; i < check.Length; i++)
    {
        if (check[i] > max)
        {
            index = i;
            max = check[i];
        }
    }
    Console.WriteLine(index);
      

  3.   

    int index_max = 0;
    int value_max = checked[0];
    for (int i = 1; i < checked.Length; ++i)
    {
        if (checked[i] > value_max)
        {
            value_max = checked[i];
            index_max = if;
        }
    }index_max就是最大数的索引