我试图编写一个程序,您可以输入“x”并在每行中获得具有6个随机数的“x”数量的行。我现在的代码给出了“x”数量的相同行的输出,每行有6个随机数。这是到目前为止我的代码多行,每个C中有6个随机数#
{
Random random_generator = new Random(DateTime.Now.Millisecond);
int random_numbers, int_games;
List<int> lst_numbers = new List<int>();
if (!int.TryParse(txt_input.Text, out int_games))
{
MessageBox.Show("Please enter valid number");
txt_input.Clear();
txt_input.Focus();
}
else
while (lst_display.Items.Count < int_games)
{
while (lst_numbers.Count < 6)
{
random_numbers = random_generator.Next(1, 45);
if (!lst_numbers.Contains(random_numbers))
{
lst_numbers.Add(random_numbers);
}
else
{
}
}
lst_display.Items.Add(string.Join(",", lst_numbers));
}
}
['For'](http://msdn.microsoft.com/zh-cn/library/ch45axte.aspx)loop。 – Sinatr 2014-10-08 09:18:39
@Reniuz你怎么错过“标识”? :)我会解决这个问题 – Leo 2014-10-08 09:18:41
@Leo [Typoglycemia](http://en.wikipedia.org/wiki/Typoglycemia):) – Reniuz 2014-10-08 09:23:58