0
我有一個程序,我加載關於狗的信息。然後,我需要找到特定品種的最古老的狗。問題是,我的程序不打印任何東西。方法將不會打印結果到控制檯
下面是代碼:
private static int findOldestAge(Dog[] dogs, string breed)
{
int maxAge = 0;
for (int i = 0; i < dogCount; i++)
{
if (dogs[i].Age > maxAge)
maxAge = dogs[i].Age;
}
return maxAge;
}
private static Dog[] findOldestDogs(Dog[] dogs, string breed, int age)
{
Dog[] oldestDogs = new Dog[MaxNumberOfDogs];
for (int i = 0; i < dogCount; i++)
{
if (dogs[i].Age == age)
oldestDogs[oldestDogCount] = dogs[i];
}
return oldestDogs;
}
static void PrintDogsToConsole(Dog[] dogs, int count)
{
for (int i = 0; i < count; i++)
{
Console.WriteLine("Vardas: {0}\nMikroschemos ID: {1}\nSvoris: {2}\nAmžius: {3}\nVeislė: {4}\nSavininkas: {5}\nTelefonas: {6}\nVakcinacijos data: {7}\nAgresyvus: {8}", dogs[i].Name, dogs[i].ChipId, dogs[i].Weight, dogs[i].Age, dogs[i].Breed, dogs[i].Owner, dogs[i].Phone, dogs[i].VaccinationDate, dogs[i].Aggressive);
}
}
這是主要的方法。我很確定數據加載正常,因爲它會打印所有信息,如果我想。
Dog[] dogs = new Dog[MaxNumberOfDogs];
Console.WriteLine("Which breed dogs count?");
breed = Console.ReadLine();
Dog[] oldestDogs = findOldestDogs(dogs, breed, findOldestAge(dogs, breed));
PrintDogsToConsole(oldestDogs, oldestDogCount);
'PrintDogsToConsole'方法在哪裏?你的程序是否會拋出任何錯誤,或者只是完成沒有輸出? –
沒有錯誤。它只是完成沒有輸出。 – noob156
FWIW您從不使用'品種'參數。 – Dai