Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我的边界在阵列之外的情况如何?_C#_Arrays - Fatal编程技术网

C# 我的边界在阵列之外的情况如何?

C# 我的边界在阵列之外的情况如何?,c#,arrays,C#,Arrays,在我的数组中,第40行,我的边界在数组之外,但我不确定如何格式化,因为这是我第一个使用多维数组的程序。请帮帮我。谢谢(第40行是array[i,0]=randomArray.Next(0100);) 名称空间练习6 { 班级计划 { 静态void Main(字符串[]参数) { OtherClass aTable=新的OtherClass();//实例化类 WriteLine(“您希望二维数组包含多少行?”); aTable.SRows=Console.ReadLine();//读取用户想要的行

在我的数组中,第40行,我的边界在数组之外,但我不确定如何格式化,因为这是我第一个使用多维数组的程序。请帮帮我。谢谢(第40行是
array[i,0]=randomArray.Next(0100);

名称空间练习6
{
班级计划
{
静态void Main(字符串[]参数)
{
OtherClass aTable=新的OtherClass();//实例化类
WriteLine(“您希望二维数组包含多少行?”);
aTable.SRows=Console.ReadLine();//读取用户想要的行数的输入
aTable.IntRows=int.Parse(aTable.SRows);//将行转换为int
Console.WriteLine(“谢谢你!你希望你的二维数组有多少列?”);
aTable.SColumns=Console.ReadLine();//读取用户想要多少列的输入
aTable.IntColumns=int.Parse(aTable.SColumns);//将列转换为int
//根据用户请求的大小设置二维数组
int[,]数组=新的int[aTable.IntColumns,aTable.IntRows];
Random randomArray=new Random();//调用Random类以请求随机数

对于(inti=0;i将循环条件更改为
i

循环从0开始,转到
aTable.IntColumns-1的值

代码就变成了

for (int i = 0; i < aTable.IntColumns; i++)
{
    array[i, 0] = randomArray.Next(0, 100); 
}
for(int i=0;i
将循环条件更改为
i

循环从0开始,转到
aTable.IntColumns-1的值

代码就变成了

for (int i = 0; i < aTable.IntColumns; i++)
{
    array[i, 0] = randomArray.Next(0, 100); 
}
for(int i=0;i
由于数组是以零为基的,因此无法达到最大值:

// This line is incorrect
for (int i = 0; i <= aTable.IntColumns; i++)
//此行不正确

对于(int i=0;i,由于数组是基于零的,因此无法达到最大值:

// This line is incorrect
for (int i = 0; i <= aTable.IntColumns; i++)
//此行不正确

for(int i=0;i错误在for循环中:

for (int i = 0; i < aTable.IntColumns; i++) // rows
{
    array[i, 0] = randomArray.Next(0, 100); // for every value in each row, insert a random number
}
for(inti=0;i

i
应该是停止标准

错误在for循环中:

for (int i = 0; i < aTable.IntColumns; i++) // rows
{
    array[i, 0] = randomArray.Next(0, 100); // for every value in each row, insert a random number
}
for(inti=0;i

i
应该是停止标准

C#数组使用零相对偏移量作为索引。这意味着对于长度为n的数组,其索引i的域是
0C#数组使用零相对偏移量作为索引。这意味着对于长度为n的数组,其索引i的域是
0这是因为您的一个大小为
s
的数组具有有效的索引
i
其中
0谢谢大家!现在,只有一件事。我修复了这两个循环…但是,现在当我尝试运行它时,它将我的数组显示为:“System.Int32[,]”为什么它没有向数组中添加任何内容?@me123-请创建一个关于数组的新问题。下面是我如何修复它的:for(int I=0;Is
的数组具有有效的索引
I
where
0谢谢大家!现在,只有一件事。我修复了这两个循环…但是,现在当我尝试运行它时,它显示了我的数组为:“System.Int32[,]”为什么它没有向数组中添加任何内容?@me123-请创建一个关于数组的新问题。以下是我如何修复它的:for(int I=0;I