下面是我的一段代码:为什么当X=61了,还不退出循环,而是继续进去造成报错,怎么回事,高手指点一二啊!
int y = 0;
for (int x = 0; x <= 60; x++)
{
string num1 = e.Row.Cells[x + 12].Text;
string num2 = e.Row.Cells[x + 13].Text;
if (num1=="")
{
num1 = "0"; if (num2=="")
{
num2 = "0";
}
}
time[y] += Convert.ToDouble(num1) / Convert.ToDouble(e.Row.Cells[10].Text) + Convert.ToDouble(num2) / Convert.ToDouble(e.Row.Cells[10].Text);
x++;
y++;
}
int y = 0;
for (int x = 0; x <= 60; x++)
{
string num1 = e.Row.Cells[x + 12].Text;
string num2 = e.Row.Cells[x + 13].Text;
if (num1=="")
{
num1 = "0"; if (num2=="")
{
num2 = "0";
}
}
time[y] += Convert.ToDouble(num1) / Convert.ToDouble(e.Row.Cells[10].Text) + Convert.ToDouble(num2) / Convert.ToDouble(e.Row.Cells[10].Text);
x++;
y++;
}
解决方案 »
- 图片上的文字显示不出来
- 用户控件发生 “Invalid postback or callback argument”错误,急!
- 【高分求解】TreeView放到虚拟主机显示不出图片来,也没法用
- windows2003下的asp.net程序发面问题向大家请教!
- 请问大虾们关于开发一个具有参数设定功能的系统的问题
- ASP.NET的安装,求助!!!!!
- FTP上传,线程问题
- OleDB Exception: record is too large
- 页面刷新出现提示框新问
- 长春哪有VS.net beta2
- 关于网站登陆的时候,Session失效的问题???(紧急!!!解决给分!!!)
- 新手问:asp.net使用session控制用户是否能访问的问题?
for (int x = 0; x <= 60; x++)
{
string num1 = e.Row.Cells[x + 12].Text;
string num2 = e.Row.Cells[x + 13].Text;
if (num1=="")
{
num1 = "0"; if (num2=="")
{
num2 = "0";
}
}
time[y] += Convert.ToDouble(num1) / Convert.ToDouble(e.Row.Cells[10].Text) + Convert.ToDouble(num2) / Convert.ToDouble(e.Row.Cells[10].Text);
// x++;
y++;
}你的x++;怎么运行了两次?
我的time我是声明了31个单元的
{
.........
x++;
y++;
if(x==60)
break;
}
或者for (int x = 0; x <= 30; x++)
string num1 = e.Row.Cells[2*x + 12].Text;
这样不就比你的两次好理解吗?而且不容易出错阿
当x=60的时候,循环到后边还有个x++;
所以x变成61,然后for (int x = 0; x <= 60; x++)
让x变成62。。 string num1 = e.Row.Cells[x + 12].Text;
string num2 = e.Row.Cells[x + 13].Text;
里边的x是不可能=61的。
报错是不是因为[x + 12].[x + 13].取得不对阿,
另外,你报什么错?你报错的时候x是多少?
然后继续经过x++; 变成61在经过括号里的x++变成62 就不继续了啊
-----------------------
你不是问X=61怎么不退出循环吗?
你程序包什么错?索引超界了?
那就不是你循环问题了。
string num1 = e.Row.Cells[x + 12].Text;
string num2 = e.Row.Cells[x + 13].Text;
上边逻辑没问题吗?