所以如果我开始我的代码一切都很好,但是当我到达零件它要求选择一个附件,我写下列表中的那个,但它只是说它不在那里,我在做什么?我想检查项目是否在数组/列表,如果它是写下来,如果不是然后告诉他们它不在那里
Console.WriteLine("Do you want any attachments on your gun?");
if(Console.ReadLine() == "Yes")
{
attachments.ToList().ForEach(i=> Console.WriteLine(i.ToString()));
Console.WriteLine("Choose A Attachment" + "\n");
string q = Console.ReadLine();
if (q != attachments.ToList().ToString())
{
Console.WriteLine("not found");
}
else if (q == attachments.ToList().ToString())
{
Console.WriteLine("attachment added");
}
}
你转换附件列表,然后检查你的把它作为一个字符串,而不是列表中的每个元素。 –