
Random类
方法1:数组来保存索引号,先随机生成一个数组位置
//产生不重复的随机数
namespace ArrayRandTwo
{
 class Program
 { 
 static void Main(string[] args)
 {
 int[] a = new int[15];
 for (int i = 0; i 
方法2: 利用Hashtable
必须引进空间名:using System.Collections; Hashtable中文称作哈希表,也叫散列表,是根据key和value进行访问存储的数据结构
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
//Hashtable的命名空间System.Collections,通过using进行引入。
namespace ArrayRandThree
{
 class Program
 {
 static void Main(string[] args)
 {
 //实例化Hashtable
 Hashtable hashtable = new Hashtable();
 Random rm = new Random();
 int RmNum = 100;
 for (int i = 0; hashtable.Count 
方法3:List 类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ArrayRandFour
{
 class Program
 {
 static void Main(string[] args)
 {
 List listNum = new List();
 Random random = new Random();
 //最小随机数
 const int Min = 100;
 //最小随机数
 const int Max = 999;
 //产生多少个随机数,这里是10个
 const int Count = 10;
 for (int i = 0; i 
 
  
                                                        秒鲨号所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈!本站将在三个工作日内改正。                        