我正在进行多项选择测验,将答案放在一个随机的地方,但由于某种原因,它从未显示所有选项。当我使用一个消息框时,它会显示所有答案都在数组中(例如:a,b,d,c),但在测验自我中,它会多次显示一些答案(例如:a,d, a,a)我无法弄清楚我的代码中出了什么问题。
public string AskQuestion()
{
question = startString + list[0];
correct = list[1].Trim();
Random antw = new Random();
string[] answers = new string[list.Length-1];
if (kind == true)
{
try
{
System.Windows.Forms.RadioButton[] radioButtons = new
System.Windows.Forms.RadioButton[list.Length];
for (int i = 1; i < list.Length; i++)
{
answers[i - 1] = list[i].Trim();
}
string[] randomAnswers = answers.OrderBy(o => antw.Next()).ToArray();
for (int i = 1; i < list.Length; i++)
{
radioButtons[i] = new RadioButton();
radioButtons[i].Text = randomAnswers[i-1].Trim();
radioButtons[i].Location = new System.Drawing.Point(6, i * 18);
grp.Controls.Add(radioButtons[i]);
}
if (list.Length == 4)
{
MessageBox.Show(randomAnswers[0] + " " + randomAnswers[1] + " " + randomAnswers[2]);
}
else if (list.Length == 5){
MessageBox.Show(randomAnswers[0] + " " + randomAnswers[1] + " " + randomAnswers[2] + " " + randomAnswers[3]);
}
}
catch (IndexOutOfRangeException ioore)
{ MessageBox.Show(ioore.Message); }
}
return question;
}