c# - 意外的 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# - EF 迁移无法删除迁移
- c# - 为什么在销毁原始对象时临时新对象为空?
- arduino - 有没有办法通过适用于 esp32 的互联网更新固件?
- vue.js - Nuxt - 如何在服务器端渲染后在客户端运行代码?
- java - ProGuard 异常“输入 jar 和输出 jar 必须不同”
- mongodb - MongoDB - 通过将一个集合中的对象嵌套到另一个集合的对象数组中来聚合两个数组
- python - Pygame Rect没有出现在显示器上
- javascript - 如何检测 window.close() 是否执行失败?
- java - 搜索具有指定属性的对象时遍历 ArrayList 两次
- reactjs - Webpack 4 Babel 和 React 在处理 JSX 文件时出错