示例#1
0
 public String RandomQuestion()
 {
     if (totalQuestionsAsked < mostQuestionsToAsk)
     {
         Random rnd            = new Random();
         int    questionNumber = rnd.Next(0, questionAndAnswers.Count);
         currentQuestionAndAnswer = questionAndAnswers.ElementAt(questionNumber);
         questionAndAnswers.RemoveAt(questionNumber);
         totalQuestionsAsked++;
         return(currentQuestionAndAnswer.Question);
     }
     else
     {
         return(null);
     }
 }
示例#2
0
        //load answers
        public void loadAnswerAndQuestions()
        {
            foreach (string file in Directory.EnumerateFiles(@"Questions", "*.txt"))
            {
                QuestionAndAnswer qa = new QuestionAndAnswer();

                int i = 0;
                foreach (string line in File.ReadLines(file))
                {
                    switch (i)
                    {
                    case 0:
                        qa.Question = line;
                        break;

                    case 1:
                        qa.CorrectAnswer = line;
                        break;

                    case 2:
                        qa.Answer1 = line;
                        break;

                    case 3:
                        qa.Answer2 = line;
                        break;

                    case 4:
                        qa.Answer3 = line;
                        break;

                    case 5:
                        qa.Answer4 = line;
                        break;
                    }
                    i++;
                }
                questionAndAnswers.Add(qa);
            }
        }