【发布时间】:2016-06-21 07:21:05
【问题描述】:
所以我试图测试我的验证,当用户输入错误的 5 位数字时,它会显示错误并返回原始表单。但是,我的代码使代码进入无限循环,因此我无法在表单上执行任何其他操作,因为循环永远不会结束。
public bool findCustomer(string accountNumber)
{
string record = Global.currentFile.getNextRecord(); //gets first record
bool okay = Global.customer.matchCustomer(accountNumber, record); //checks if it matches
while (!okay == true) //if it does not match, get next record and check again until it reaches end of file
{
record = Global.currentFile.getNextRecord();
okay = Global.customer.matchCustomer(accountNumber, record);
}
return okay;
}//end method
这是从另一个类获取记录的方法
public string getNextRecord()
{
string nextRecord = String.Empty;
while ((nextRecord = reader.ReadLine()) != null)
{
return nextRecord;
}
return nextRecord;
}// end getNextRecord
这是文本文件
12345 * Shrek * 1209 * 100000 * 50000
12077 * Sammy Wheeler * 1207 * 5000 * 0
99999 * The Big Grump * 1298 * 1500000 * 1500000
13579 * Brooks Robinson * 5555 * 225000 * 225000
24680 * Johnny Unitas * 1919 * 60000 * 34000
68420 * Y. A. Tittle * 1414 * 42000 * 12000
23456 * Hilary Clinton * 2222 * 65000 * 123456
23232 * Julianne Baird * 1234 * 145000 * 12321
【问题讨论】:
-
我强烈推荐你使用数据库系统。如果您需要将记录存储在文件中,请使用 SQLite。你为什么要重新发明轮子?
标签: c# .net file while-loop