一种可能的(简单)方法:
public class Quiz
{
public string Question { get; private set; }
public string Answer { get; private set;}
public Quiz(string question, string answer)
{
Question = question;
Answer = answer;
}
}
然后后来:
// Create a dictionary
Dictionary<string, List<Quiz>> quizDictionary = new Dictionary<string, List<Quiz>>();
// Create a category
List<Quiz> sportsQuiz = new List<Quiz>();
// Add questions & answers to the category
sportsQuiz.Add(new Quiz("Whats the question?", "It's the answer"));
// Add the category to your quiz dictionary
quizDictionary.Add("Sports", sportsQuiz);
// Select a category
List<Quiz> randomQuiz = quizDictionary["Sports"];
// Do something with the category
Quiz randomQA = randomQuiz[0];
Ask(randomQA.Question);
if (answer == randomQA.Answer)
// correct answer
else
// wrong answer