我試圖通過他們居住的城鎮搜索存儲在文本文件中的客戶帳戶。有三個客戶帳戶都與不同的城鎮有關。我認爲程序找到了正確的客戶,因爲它確實返回數據寫入屏幕,但不是全部。這些圖像更好地解釋了它。試圖將它們嵌入,但沒有點使用流式閱讀器僅讀取部分文本的.txt文件後,寫入控制檯的文本
文本文件的內容:
當生活在利物浦客戶搜索(雖然圖像犯規表現出來,光標開始閃爍5線DOB下文)
搜索貝爾法斯特顧客。注意它拿起coreect DOB但不對客戶號碼和姓氏。(伊利諾伊放在commentit鏈接不會讓我上傳超過2個鏈接)
繼承人的方法::
static void FindTown(CustomerStruct[] CustomerDeats)
{
string City;
bool CityMatch = false;
Console.Clear();
begin:
try
{
Console.WriteLine("Please enter the customers Town ");
City = Console.ReadLine();
}
catch
{
Console.WriteLine("Failed. Please try again.");
goto begin;
}
var pathToTown = @"..\..\..\Files\Customer.txt";
using (StreamReader sr = new StreamReader(pathToTown))
while (!CityMatch)
{
{
RecCount = 0;
CustomerDeats[RecCount].Town = sr.ReadLine();
if (City == CustomerDeats[RecCount].Town)
{
Console.WriteLine("\n\n");
CityMatch = true;
CustomerDeats[RecCount].CustomerNo = sr.ReadLine();
Console.WriteLine(CustomerDeats[RecCount].CustomerNo);
CustomerDeats[RecCount].Surname = sr.ReadLine();
Console.WriteLine(CustomerDeats[RecCount].Surname);
CustomerDeats[RecCount].Forename = sr.ReadLine();
Console.WriteLine(CustomerDeats[RecCount].Forename);
CustomerDeats[RecCount].Street = sr.ReadLine();
Console.WriteLine(CustomerDeats[RecCount].Street);
CustomerDeats[RecCount].Town = sr.ReadLine();
Console.WriteLine(CustomerDeats[RecCount].Town);
CustomerDeats[RecCount].DOB = sr.ReadLine();
Console.WriteLine(CustomerDeats[RecCount].DOB);
Console.ReadKey();
}
RecCount++;
}
}
}
的代碼
http://i1370.photobucket.com/albums/ag266/Aaron_McCauley/3_zpsc6e9e525.png – COYG
在任何現代編程語言中使用'goto'很少是個好主意。它會導致難以理解和維護的非結構化代碼。 –
我會記住這一點,並確保我熟悉它。 – COYG