public static void getList()
{
//写一个长度为10 的集合,要求里面存放10个随机数(0-9)
//要求数字不能重复
Random rd = new Random();
ArrayList list = new ArrayList();
for (int i = 0; i < 10; i++)
{
int number = rd.Next(0,10);
if (!list.Contains(number))
{
list.Add(number);
}
else
{
i--;
}
}
for (int i = 0; i < 10; i++)
{
Console.WriteLine(list[i]);
}
Console.ReadLine();
}
时间: 2024-11-12 00:08:51