我写了如下一段代码:
string loadCurrentpath = Directory.GetCurrentDirectory();
string loadpatch = loadCurrentpath + @"\bin\tab.txt";
string loadstrline;
string loadclassname;
FileStream loadfs = new FileStream(loadpatch,FileMode.Open,FileAccess.ReadWrite,FileShare.Read);
StreamReader loadsr = new StreamReader(loadfs,System.Text.Encoding.Default);
loadstrline = loadsr.ReadLine();
char loadtabflag0 = loadstrline[loadstrline.Length-1];
string loadtabflag = loadtabflag0.ToString();
MessageBox.Show(loadtabflag,"提示");
loadclassname = loadstrline.Substring(0,loadstrline.Length-2);
MessageBox.Show(loadclassname,"提示");
MessageBox.Show(loadstrline,"提示");
.................................
messagebox是我用来测试逻辑是否正确的语句
编译执行后 跳出的messagebox显示的都完全正确,但是光标就停在“char loadtabflag0 = loadstrline[loadstrline.Length-1];”这一行,提示未处理的“System.IndexOutOfRangeException”类型的异常出现在 mscorlib.dll 中。其他信息: 索引超出了数组界限请问大虾这是怎么回事?