如果我想讓程序生成一個隨機數,然後re-read/loop
else if statement
,直到它找到與此類似的語句,如果(button1.Text == "")
,該隨機數只需要去高達9創建一個隨機循環,直到一個語句爲真
這是我的代碼,
private void button1_Click(object sender, EventArgs e)
{
var rc = new Random();
storeRI = rc.Next(1, 9);
if (storeRI == 1)
{
if (button1.Text == "")
{
button1.Text = "X";
}
else
{
//Need to generate another random number
//And read the else if statement again... how?
}
}
else if (storeRI == 2)
{
if (button1.Text == "")
{
button1.Text = "X";
}
else
{
//Need to generate another random number
//And read the else if statement again... how?
}
}
檢查:http://stackoverflow.com/questions/10688044/filling-a-array-with-uniqe-random-數字之間的0-9之間的尖銳 – Dejo
我真的不明白這段代碼的目的。 – daryal
我想到的第一件事是'while循環'。然後,我瀏覽並查看其他人的回答,以及賓果!我們有同樣的想法。 'while(I_havent_find_the_answer)do' – alont