2013-02-10 95 views
2

嗯,我正在读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(); 
+1

出于调试的目的,您是否确认'KeyWords'和'invariantText'包含期望值?使用调试器或'Console.WriteLine()'。 – 2013-02-10 02:56:25

+0

让这个答案花花公子。 因为我确实打开了一个带有结果的消息框,并且在下一个问题加载之前忘记清除'KeyWords'阵列列表<3 – Cacoon 2013-02-10 03:16:27

回答

0

感谢第一个评论我的问题。 我放弃了,我从来没有真正清除数组列表,请确保在做这个检查后清除数组列表,以便在关键字列表中没有获得更多的值,然后通缉。

KeyWords.Clear(); 
1

进行调试,确认KeyWordsinvariantText包含预期值。使用调试器或者Console.WriteLine().

这就是单元测试变得有价值的地方。 NUnit或MSTest可用于C#/ VS开发。

+0

感谢您的回答和评论。 感谢我的接触,我从来没有真正清除ArrayList <3 Works现在完美。 1000谢谢你! – Cacoon 2013-02-10 03:25:59

相关问题