我正在制作一个WP7应用程序,当用户点击图像时,它会随机决定他们将获得什么。
现在,我有以下代码:string firstdoor = "";
string seconddoor = "";
string thirddoor = "";
和
string prize1 = "vacation to Hawaii with all expenses covered";
string prize2 = "used glue stick";
string prize3 = "pile of dog dung";
string prize3 = "vacation to Europe with all expenses covered";
string prize3 = "million dollars";
string prize3 = "blank CD";
string prize3 = "temporary tattoo";
string prize3 = "nickel";
string prize3 = "dime";
和
我想做的是将door
随机分配给prize
。
例如,当用户点击图像时,将dime
分配给thirddoor
,将nickel
分配给firstdoor,并且将million dollars
分配给secondoor
。
最佳答案
以下是对我来说最有意义的步骤(不会为您编写所有代码):
将所有奖金字符串放入数组中。
生成介于0和最大奖品数量之间的三个随机数。
从奖品阵列中为每个门分配每个随机数的奖品。
...
利润!
编辑
实际上,这里有一些代码可以帮助您:
var randomGenerator = new Random();
string[] prizes = { "vacation to Hawaii with all expenses covered",
"used glue stick",
"pile of dog dung",
"vacation to Europe with all expenses covered" };
string firstDoor = prizes[randomGenerator.Next(prizes.Length)];
string secondDoor = prizes[randomGenerator.Next(prizes.Length)];
string thirdDoor = prizes[randomGenerator.Next(prizes.Length)];
关于c# - 在C#中为WP7选择随机字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5518039/