C#格式错误的代码? [英] C# badly formatted code?
本文介绍了C#格式错误的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
This is my code
//split the action in to lines
StreamReader sr = new StreamReader("C:\\Users/Kyle/Desktop/jhkhj/Year11-ActionElectivites.txt");
String line = sr.ReadToEnd();
string[] split = line.Split(',');
int ReadAllActionLines = 0;
while (ReadAllActionLines <= split.Length)
{
ActionListBox.Items.Add(split[ReadAllActionLines]);
ReadAllActionLines = ReadAllActionLines + 1;
}
sr.Close();
//split the survice in to lines
StreamReader sr2 = new StreamReader("C:\\Users/Kyle/Desktop/jhkhj/Year11-SurviceElectivites.txt");
String line2 = sr2.ReadToEnd();
string[] split2 = line2.Split(',');
int ReadAllActionLines2 = 0;
while (ReadAllActionLines2 <= split2.Length)
{
SurviceListBox.Items.Add(split2[ReadAllActionLines2]);
ReadAllActionLines2 = ReadAllActionLines2 + 1;
}
sr2.Close();
由于某种原因,代码停在
sr.Close();
但我不知道为什么,它应该继续下去!在读完sr之后,它应该读取sr2,但它不能有人请帮助我不明白为什么它不读sr2
for some reason the code stops at
sr.Close();
but i dunno why, it should be keep going! after it has read sr it sould read sr2 but it dosen''t can some one please help i don''t understand why its not reading sr2
推荐答案
它确实不要停止您的代码中很可能有例外。
将此代码放入try-catch
块中,然后检查错误。
It does not stop. There is most likely an exception in your code.
Put this code in atry-catch
block and then check the error.
请使用下面的try catch块并获得确切的例外: -
Please use try catch block like below and get the exact exception :-
try
{
//split the action in to lines
StreamReader sr = new StreamReader("C:\\Users/Kyle/Desktop/jhkhj/Year11-ActionElectivites.txt");
String line = sr.ReadToEnd();
string[] split = line.Split(',');
int ReadAllActionLines = 0;
while (ReadAllActionLines <= split.Length)
{
ActionListBox.Items.Add(split[ReadAllActionLines]);
ReadAllActionLines = ReadAllActionLines + 1;
}
sr.Close();
//split the survice in to lines
StreamReader sr2 = new StreamReader("C:\\Users/Kyle/Desktop/jhkhj/Year11-SurviceElectivites.txt");
String line2 = sr2.ReadToEnd();
string[] split2 = line2.Split(',');
int ReadAllActionLines2 = 0;
while (ReadAllActionLines2 <= split2.Length)
{
SurviceListBox.Items.Add(split2[ReadAllActionLines2]);
ReadAllActionLines2 = ReadAllActionLines2 + 1;
}
sr2.Close();
}
catch(Exception ex)
{
Messagebox.Show(ex.stacktrace);
}
这篇关于C#格式错误的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文