作者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