软件编程
位置:首页>> 软件编程>> C#编程>> 向一个数组中插入一个1~100的随机数

向一个数组中插入一个1~100的随机数

作者:whsnow  发布时间:2022-03-29 16:12:22 

标签:数组,随机插入

namespace ConsoleApplication2
{
 class Program
 {

static void Main(string[] args)
   {
     List<int> list = new List<int>();
     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();
   }
 }
}
0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com