我得到了一个超出范围异常的奇怪索引。
这是我的代码片段:
string[] st2 = **An Array of up to 10**;
// If not enough in st2, add from st
if (st2.Length < 10)
{
string[] st = **An Array of up to 10**;
try
{
int index = 0;
for (int i = st2.Length - 1; i < 10; i++)
{
st2[i] = st[index];
index = index + 1;
}%%%
}
catch (IndexOutOfRangeException)
{
}
}
我放置了 try 和 catch 以查看是否可以简单地忽略异常,但这不起作用。
在 %%% 处抛出异常。有任何想法吗?我进行调试只是为了确保它不是任何一个数组,并且在这两种情况下, i 和 index 都是可以接受的。(即使 st 的长度被确认为 10,也会在 index = 1 处抛出)