源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-08-23 08:00 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:向一个数组中插入一个1~100的随机数
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)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部