string[] strs = line.Split(',');
if (strs[1] == "BEAM"){}
else if (int.Parse(strs[7]) == 0){}
else{}编译可以成功,运行时提示数组越界了 是怎么回事
读入的数据如下
2, WALL , 14, 6, 1, 2, 326, 325, 2, 1
33, BEAM , 14, 22, 416, 32, 0
173, WALL , 14, 2, 174, 164, 798, 811, 2, 30
404, PLATE , 2, 11, 381, 382, 361, 0, 2
if (strs[1] == "BEAM"){}
else if (int.Parse(strs[7]) == 0){}
else{}编译可以成功,运行时提示数组越界了 是怎么回事
读入的数据如下
2, WALL , 14, 6, 1, 2, 326, 325, 2, 1
33, BEAM , 14, 22, 416, 32, 0
173, WALL , 14, 2, 174, 164, 798, 811, 2, 30
404, PLATE , 2, 11, 381, 382, 361, 0, 2
{
int i;
if (l.Contains("BEAM"))
{
}
else if(int.TryParse(l,out i) && i==0)
{
}
}
要是觉得不保险,就写多个if语句吧
if (strs[1] == "BEAM"){}if (!(strs[1] == "BEAM") && int.Parse(strs[7]) == 0){}