第1个回答 推荐于2016-09-16
string temp = ""; //临时容器
int n =0;
Random rd = new Random();
while(n <10)
{
int num = rd.Next(1, 10); //产生1~9的随机数
if(temp.IndexOf(num.ToString())>=0) //判断容器里面有没有刚产生的数
{
n = n; // 已经有了就重新执行循环
}
else
{
temp += num.ToString();//没有将新产生的数装进容器
Console.WriteLine(num.ToString());//输出数
n++;
}
}
Console.ReadLine();本回答被提问者采纳