作者angelfox (Come to Dady!)
看板C_Sharp
標題[問題] 一些小問題集
時間Sat Mar 14 23:54:37 2009
1.
public bool GameOver(int[] x)
{
if (x[0] == expectation[0] && x[1] == expectation[1])
{
return true;
}
else
{
return false;
}
}
當我if裡面寫 x == expectation 時,輸出的值就是false
我實在不太知道這有什麼差別,請指教一下
2.
public void SetRand()
{
for (int i = 0; i < 4; i++)
{
random[i] = rand.Next() % 10;
//each two numbers cannot be the same
while (i == 1 && random[1] == random[0])
{
random[i] = rand.Next() % 10;
}
while (i == 2 && (random[2] == random[0]
|| random[2] == random[1]))
{
random[i] = rand.Next() % 10;
}
while (i == 3 && (random[3] == random[0]
|| random[3] == random[1] || random[3] == random[2]) )
{
random[i] = rand.Next() % 10;
}
}
}
這是部份的程式碼
任兩數不能相同的地方實在不知道怎麼做了,只好土法煉鋼
不知道有什麼比較好的方法?
初學程式
最近才開始看書
請大家多關照
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.252.38
1F:推 toki:x是陣列,expectation也是陣列,比 x == expectation 時 03/15 01:54
2F:→ toki:比的是這兩個陣列是不是同一個物件,而不是比裡面的值 03/15 01:55
3F:→ angelfox:原來如此 多謝 03/15 14:43