[英]c# Trying to loop through a string array , compare a string to find, and output the found string
在一系列書籍中查找書籍的程序。 這個代碼沒有找到這本書?
string aBookToFind;
string[] listOfBooks = { "Jane Eyre", "Catch22", "Dunkirk","Kidnapped", "Treasure Island" };
aBookToFind=Console.ReadLine();
for(int i=0;i<5;i++){
Console.WriteLine("Book : "+listOfBooks[i]);
if (aBookToFind == listOfBooks[i])
{Console.WriteLine("Found Book "+ listOfBooks[i];
}
}
第 7 行“;”之前缺少括號 {Console.WriteLine("Found Book "+ listOfBooks[i];
修復此問題並使用輸入運行代碼后: Catch22
The Output 為:
Book : Jane Eyre
Book : Catch22
Found Book Catch22
Book : Dunkirk
Book : Kidnapped
Book : Treasure Island
所以我會說除了缺少的“)”它按預期工作。 如果您期待另一個 output,可以將其添加到您的問題以獲得更准確的答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.