嗯,我正在读Check if the string contains all inputs on the list 而且试了一下,但是当我有这样的事情的一个基本问题,如“谁发现Austrlia” ,如果我把钥匙词语的答案为'船长,厨师“这可能会说我错了。检查列表包含在字符串中的所有单词
任何想法什么即时做错了;代码即时通讯使用:
GivenAnswer = textBox1.Text;
String invariantText = textBox1.Text.ToUpperInvariant();
bool matches = KeyWords.All(kw => invariantText.Contains(kw.ToUpperInvariant()));
if (matches)
{
correct++;
if (InstantResult) { MessageBox.Show("Questions Answered Correctly", "Answer Results", MessageBoxButtons.OK, MessageBoxIcon.Information); }
}
else
{
incorrect++;
if (InstantResult) { MessageBox.Show("Question Answered Wrong, sorry!", "Answer Result", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }
}
Study_Helper.Form1.QuestionResults.Add(Question + "|" + (matches ? "true" : "false") + "|" + (Exact? "N/A" : KeyWords_Found()) + "|" + (Hint_Used ? "true" : "false") + "|" + GivenAnswer.ToLowerInvariant());
LoadUp();
textBox1.Clear();
textBox1.Focus();
出于调试的目的,您是否确认'KeyWords'和'invariantText'包含期望值?使用调试器或'Console.WriteLine()'。 – 2013-02-10 02:56:25
让这个答案花花公子。 因为我确实打开了一个带有结果的消息框,并且在下一个问题加载之前忘记清除'KeyWords'阵列列表<3 – Cacoon 2013-02-10 03:16:27