【问题标题】:Method without repeat [duplicate]不重复的方法[重复]
【发布时间】:2016-07-31 02:26:08
【问题描述】:

我有一个名为 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);
}

当您点击正确的问题时,问题会发生变化,但问题和答案会重复。我怎样才能做到不重复?

【问题讨论】:

  • 您需要包含有关当前行为和您期望的行为的更多信息。

标签: c# list class if-statement methods


【解决方案1】:

如果我猜对了,你想一次性完成所有问题吗?如果是这样,请列出代表问题的整数。问题通过后,将其从列表中删除。像这样:

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);

【讨论】:

  • Korhak : 我应该在哪里添加该方法 q.questions("1+1 =", "1", "2", "3", "4", Button2) ??跨度>
  • 我不知道你程序的整个结构,所以你必须自己考虑一下。您保持结构不变,只需将行替换为 int qu = ... 最后您调用 questions.Remove(qu) 然后可以再次调用该方法。
猜你喜欢
  • 2017-05-22
  • 1970-01-01
  • 1970-01-01
  • 2013-09-23
  • 2018-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多