private void QuestionAnswer_Load(object sender, EventArgs e)
{
txtQuestion.Enabled = false;
txtQuestion.BackColor = Color.White;
grpMultipleChoice.Enabled = false;
grpSingleChoice.Enabled = false;
btnCheckAnswer.Enabled = false;
btnNext.Enabled = false;
btnQuit.Enabled = false;
//force student to enter registration details
if (txtStudentName.Text == "" && txtStudentNumber.Text == "" && txtModuleNumber.Text == "")
{
btnStart.Enabled = false;
MessageBox.Show("You must enter your registration details at the upper right corner");
}
//declare a list
lstNumbers = new ArrayList();
//create a random number generator
Random rndNumber = new Random();
//generate 70 random numbers
//int number = (int)(rndNumber.NextDouble() * 69) + 1;
//lstNumbers.Add(number);
///use this counter to loop whenever a number is generated
int count = 0;
int maximumNumber = 69;
///disable answer button
btnCheckAnswer.Enabled = false;
do
{
int number = (int)(rndNumber.NextDouble() * maximumNumber) + 1;
lstNumbers.Add(number);
if (!lstNumbers.Contains(number))
{
lstNumbers.Add(number);
}
count++;
} while (count <= 15 * 70);//
btnCheckAnswer_Click(sender, e);
return lstNumbers;//returns once list is built
}
说明:我创建了一个数组列表,允许我在 1-70 之间随机生成,但注意到我的数字有些重复。为了防止这种情况,我注意到我在下面收到一条错误消息:
错误 1 由于 'wwTestAppV1.GenKnow.QuestionAnswer_Load(object, System.EventArgs)'返回 void,return 关键字后面不能跟对象表达式
我已尽我所能解决这个问题。当我删除此语句但显示重复值时,程序运行良好。能否请你帮忙?