C#声明一个100大小的数组 随机生成1-100之间不重复的数

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace arrayTest
{
    //C#声明一个100大小的数组 随机生成1-100之间不重复的数
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = new int[100];
            ArrayList newArrayList = new ArrayList();
            Random r = new Random();
           
            for (int i = 1; i < 101; i++)
            {
                int sum=r.Next(1, 101);
                array[i] = sum;
                while (newArrayList.Count <= 100)
                {
                    if (!newArrayList.Contains(sum))
                    {
                        newArrayList.Add(sum);
                    }
                }
            }
            for (int j = 0; j < 100; j++)
            {
                array[j] =(int) newArrayList[j];
                Console.Write("{0}",array[int]);
               
            }
            Console.ReadKey();
    
        }
    }
}
运行结果:
65,93,59,70,94,7,91,25,64,28,95,73,87,11,60,47,62,40,48,84,77,86,99,17,69,4,39,8
3,97,74,24,100,15,2,76,37,78,42,9,33,41,13,22,23,92,29,31,89,61,54,3,53,68,71,72
,85,52,80,46,82,27,14,56,88,49,51,21,63,79,75,96,57,6,58,44,66,30,19,16,35,8,5,8
1,55,26,18,90,43,1,50,36,10,38,20,98,12,32,67,34,45,请按任意键继续. . .

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邹琼俊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值