繁体   English   中英

c# 尝试遍历字符串数组,比较要查找的字符串,output 找到的字符串

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM