首页 > 解决方案 > 意外的 System.IndexOutOfRangeException?尝试按其在数组中的位置打印值

问题描述

我目前正在尝试在 C# 中创建一个冒泡排序系统,为此我需要能够根据其位置从数组中取出一个值。但是,当我输入 int a = (array[0]) 应该给我数组中的第一个值时,我反而得到一个不同的值,通常是第三个?请帮我找到下面复制的代码!

using System;
public class Bubble_Sort
{
    public static void Main(string[] args)
    {
        int[] numbers = new int[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        int i = (numbers[0]);
        Console.WriteLine(numbers[i]);
        int a = (numbers[7]);
        Console.WriteLine(numbers[a]);
        Console.Read();
    }
}

任何帮助表示赞赏,这真的让我很头疼!

亚历克纳珀。

标签: c#

解决方案


推荐阅读