逐语句调试出错,但编译时通过

chocolateboy 2005-05-25 03:03:41
调试时出现 myArr “未定义的值”错误,实在令人费解

using System;


public class MultiArrayApp
{
protected int [ , ] arrNum;
protected int curValue;

public MultiArrayApp()
{
curValue = 10;
arrNum = new int [2,curValue];

for(int i=0;i<arrNum.GetLength(0);i++)
{
for(int j=0;j<arrNum.GetLength(1);j++)
{
arrNum[i,j] = i * 100 + j;
}
}
}

public void PrintArrayApp()
{
for(int i=0;i<arrNum.GetLength(0);i++)
{
for(int j=0;j<arrNum.GetLength(1);j++)
{
Console.WriteLine("\narrNum[{0},{1}] = ", arrNum[i,j]);
}
}
}
}

public class MainCls
{
public static void Main()
{
MultiArrayApp myArr = new MultiArrayApp();
myArr.PrintArrayApp();
}
}

...全文
111 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lilidan 2005-06-17
  • 打赏
  • 举报
回复
Console.WriteLine("\narrNum[{0},{1}] = ", arrNum[i,j]);
错误的原因是这里{1}没有赋予值。
而且不推荐这样写,因为编译器无法检查你的参数个数。
lilidan 2005-06-17
  • 打赏
  • 举报
回复
修改成这样:
public void PrintArrayApp()
{
for(int i=0;i<arrNum.GetLength(0);i++)
{
for(int j=0;j<arrNum.GetLength(1);j++)
{
Console.WriteLine("\narrNum[{0},{1}] = {2}",i,j,arrNum[i,j]);
}
}
}
chocolateboy 2005-06-17
  • 打赏
  • 举报
回复
构选函数不能返回任何值
syliuxybj 2005-06-17
  • 打赏
  • 举报
回复
个人认为public MultiArrayApp()方法应该返回arrNum[,]。
chocolateboy 2005-06-17
  • 打赏
  • 举报
回复
看不出来有什么问题,算我笨,楼上的讲详细点吧,我菜得很。看不出数组元素引用超出了范围,为什么楼上的法眼都一致认为i或j超出了范围?
zhongwanli 2005-06-16
  • 打赏
  • 举报
回复
楼上
fuyiyong 2005-06-16
  • 打赏
  • 举报
回复
逻辑错误!!
i或j超出了范围
xiaha3 2005-06-16
  • 打赏
  • 举报
回复
i或j超出了范围
就是说i>6了,你用arrNum[7,10]系统就会出错
chocolateboy 2005-06-16
  • 打赏
  • 举报
回复
oop~
chocolateboy 2005-05-26
  • 打赏
  • 举报
回复
d
chocolateboy 2005-05-25
  • 打赏
  • 举报
回复
关心一下基础性的问题,谢谢。up!~~~

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧