我写了如下一段代码:
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 中。其他信息: 索引超出了数组界限请问大虾这是怎么回事?
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 中。其他信息: 索引超出了数组界限请问大虾这是怎么回事?
解决方案 »
- C#下怎样取到JSon文件里面的部分属性
- 文件路径读取问题
- string was not recognized as a valid datetime.................
- 一个SQL问题,帮忙看看,非常感谢!
- C#想做计算器出现的问题
- DataList的事件问题,大家帮忙,谢谢
- c#绘图彩图
- 在asp.net 2005怎么设置登陆页面?
- 没有标题栏的窗体的移动算法?
- 关以资源回收
- 怎样让单选框<asp:RadioButton id=Radio1 Text="合" GroupName="caizhi" runat="server" />不可点击?
- 我想做一个图形化的流程设计软件,有很多绘图的问题请教
tab.txt中没有字符的话,错误是:未将对象引用设置到实例。(加个判断好了,看这个文件是否为空。)