当前位置: 编程技术>.net/c#/asp.net
向一个数组中插入一个1~100的随机数
来源: 互联网 发布时间:2014-10-31
本文导语: namespace ConsoleApplication2 { class Program { static void Main(string[] args) { List list = new List(); Random ran = new Random(); while(true) { if (list.Count >= 100) { break; }...
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
List list = new List();
Random ran = new Random();
while(true)
{
if (list.Count >= 100)
{
break;
}
int s = ran.Next(1, 101);
if (!list.Contains(s))
{
list.Add(s);
}
}
list.Sort();
foreach (int i in list)
{
Console.Write(i + " ");
}
Console.ReadKey();
}
}
}