方法无需重复

时间:2016-04-09 21:40:58

标签: c# list class if-statement methods

我有一个名为QuestionsAll的类,带有构造函数:

QuestionsAll(label question, Button b1, Button b2, Button b3, Button b4)

和方法叫做:

questions(string question, string answer1, string answer2, string answer3, string answer4, Button correctanswer)   

我如何在表单中使用它:

void NewQuestion()    
{
    Random rd = new Random();
    int qu = rd.Next(0,4)
    QuestionsAll q = new QuestionsAll(label1,Button1,Button2,Button3,Button4) //my question will be in label1, answer1 in Button1......)

    if(qu == 1) q.questions("1+1 =", "1", "2", "3", "4", Button2);
    if(qu == 2) q.questions("1+2 =", "1", "2", "3", "4", Button3);
}

当您点击正确的问题时,问题会发生变化,但问题和答案会重复出现。我怎么能不重复呢?

1 个答案:

答案 0 :(得分:2)

如果我做对了,你想要一次解决所有问题吗?如果是,请创建表示问题的整数列表。问题通过后,将其从列表中删除。像这样:

List<int> questions = new List<int>();
for (int i = 0; i < 5; i++){
    list.add(i);
}
//...
int qu = rd.Next(0, questions.Count);
//... Question is answered
questions.Remove(qu);