我附上下面的代码,我得到IndexOutOfRangeException A部分没有被处理,我试过的try-catch如下,但现在我得到类型的IndexOutOfRangeException多维数组
“第一次机会异常“ System.IndexOutOfRangeException'发生在app.Form6.ZMove(String s1,String s2)中的app.exe 中C:\ Users \ Rahul Taneja \ Documents \ Visual Studio 2010 \ Projects \ app \ app \ Form6.cs中:第136行“
在堆栈跟踪任何一个可以告诉我为什么t正在发生,可能会有什么解决方案?
public void ZMove(string s1, string s2)
{
//Move 2-1-4-3
int j = Int32.Parse(s1);
int k = Int32.Parse(s2);
for (int l = 0; l < k; l++)
{
try
{
swap(array[2][j], array[1][j]); ///Part A
swap(array[1][j], array[4][j]);
swap(array[4][j], array[3][j]);
swap(array[3][j], array[2][j]);
}
catch (IndexOutOfRangeException e)
{
MessageBox.Show(e.StackTrace);
//throw;
}
}
}
private void swap(char[] p1, char[] p2)
{
//throw new NotImplementedException();
int l = p1.Length;
for (int i = 0; i < l; i++)
{
char temp = p1[i];
p1[i] = p2[i];
p2[i] = temp;
}
}
哪行引发异常?这条线上阵列的形状是什么?简单的答案是,在代码中使用的数组索引之一不存在于数组中。 – David 2012-07-19 15:57:39
我提到过,它是A部分,数组是3D数组 – Rahul 2012-07-19 15:58:28
抛出异常时'array'值的形状是什么?和'j'的价值?数组的第一维没有索引2或1,或者第二维没有索引“j”。 – David 2012-07-19 16:00:12