【发布时间】:2018-07-31 12:19:24
【问题描述】:
我想为用户可以赢得由他们的 ID(1、2、3 等)指定的项目的事件绘制一个随机名称。随机名称部分现在还可以,但我怎样才能显示结果:
The ID : 1 winner is: 'the random name'
The ID : 2 winner is: 'the random name'
etc...
till ID : 27
static void Main(string[] args)
{
string[] Names = { "Erik", "Levente", "Noel", "Áron", "Krisztián", "Kristóf", "Bence", "Roland", "Máté", "László", "Bálint" ,
"Regina", "Brigitta", "Gréta", "Hédi", "Hanna", "Boglárka", "Jázmin", "Réka", "Alexandra", "Rebeka", "Lili", "Luca", "Zsófi"};
List<string> alreadyUsed = new List<string>();
Random r = new Random();
while (alreadyUsed.Count < Names.Length)
{
int index = r.Next(0, Names.Length);
if (!alreadyUsed.Contains(Names[index]))
{
alreadyUsed.Add(Names[index]);
Console.WriteLine("The ID : 1 winner is: " + Names[index]);
}
}
Console.ReadKey(true);
}
【问题讨论】:
-
为什么特别想使用
++i? -
你没有一个名为
i的变量,你到底想达到什么目的? -
@Sayse 他试图在
The ID : 1 winner is计数 -
值得一提的是,您只有 24 个名字,但您想直到 ID:27?