首页上一页 1 下一页尾页 1 条记录 1/1页
标准教程Ex04_08在我机器上调试出现错误
发表在C#图书答疑
2009-07-17
是否精华
是
否
版块置顶:
是
否
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ex04_08
{
class Program
{
static void Main(string[] args)
{
int row = 0, col = 0;
Console.Write("请输入二维数组的行数:");
row = Convert.ToInt32((Console.ReadLine()));
Console.Write("请输入二维数组的列数:");
col = Convert.ToInt32((Console.ReadLine()));
Console.WriteLine("请输入二维数组各元素值:");
int[,] arr2 = new int[row, col];
for (int i = 0; i < row; i++)
for (int j = 0; j < arr2.GetUpperBound(arr2.Rank - 1) + 1; j++)
arr2[i, j] = Convert.ToInt32((Console.ReadLine()));
Console.WriteLine("显示输入的二维数组:");
for (int i = 0; i < row; i++)
{
for (int j = 0; j < arr2.GetUpperBound(arr2.Rank - 1) + 1; j++)
Console.Write(arr2[i, j] + " ");
Console.WriteLine();
}
}
}
}
当我输入行数为3,列数为4时,出现调试错误,好像是什么数组越界问题
未处理IndexOutOfRangeException
索引超出了数组界限
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ex04_08
{
class Program
{
static void Main(string[] args)
{
int row = 0, col = 0;
Console.Write("请输入二维数组的行数:");
row = Convert.ToInt32((Console.ReadLine()));
Console.Write("请输入二维数组的列数:");
col = Convert.ToInt32((Console.ReadLine()));
Console.WriteLine("请输入二维数组各元素值:");
int[,] arr2 = new int[row, col];
for (int i = 0; i < row; i++)
for (int j = 0; j < arr2.GetUpperBound(arr2.Rank - 1) + 1; j++)
arr2[i, j] = Convert.ToInt32((Console.ReadLine()));
Console.WriteLine("显示输入的二维数组:");
for (int i = 0; i < row; i++)
{
for (int j = 0; j < arr2.GetUpperBound(arr2.Rank - 1) + 1; j++)
Console.Write(arr2[i, j] + " ");
Console.WriteLine();
}
}
}
}
当我输入行数为3,列数为4时,出现调试错误,好像是什么数组越界问题
未处理IndexOutOfRangeException
索引超出了数组界限