我似乎得到一個OutOfRangeException
,指出以下:「索引出表限制」(不準確的翻譯,我的VS是法國人),這是相關代碼:得到不正確的OutOfRange例外
pntrs = new int[Pntrnum];
for (int i = 0; i < Pntrnum; i++)
{
stream.Position = Pntrstrt + i * 0x20;
stream.Read(data, 0, data.Length);
pntrs[i] = BitConverter.ToInt32(data, 0);
}
Strs = new string[Pntrnum];
for (int i = 0; i < Pntrnum; i++)
{
byte[] sttrings = new byte[pntrs[i + 1] - pntrs[i]];//the exception occures here !
stream.Position = pntrs[i];
stream.Read(sttrings, 0, sttrings.Length);
Strs[i] = Encoding.GetEncoding("SHIFT-JIS").GetString(sttrings).Split('\0')[0].Replace("[FF00]", "/et").Replace("[FF41]", "t1/").Replace("[FF42]", "t2/").Replace("[FF43]", "t3/").Replace("[FF44]", "t4/").Replace("[FF45]", "t5/").Replace("[FF46]", "t6/").Replace("[FF47]", "t7/").Replace("[0a]", "\n");
ListViewItem item = new ListViewItem(new string[]
{
i.ToString(),
pntrs[i].ToString("X"),
Strs[i],
Strs[i],
});
listView1.Items.AddRange(new ListViewItem[] {item});
}
我做錯了什麼?
問題出在'pntrs [i + 1]'。當pntrs處於最終索引時,您將添加'1',這會將其推出界限。 – keyboardP
'i + 1'將超出'pntrs'的範圍 –