C# 一个长度为100的int数组,插入1-100的随机数,不能重复,如何写

int[] intArr = new int[100]; 
ArrayList myList = new ArrayList();
Random rnd = new Random();
while (myList.Count < 100)
{
  int num = rnd.Next(1, 101);
  if (!myList.Contains(num))
  myList.Add(num);
}
for (int i = 0; i <100; i++)
{
  intArr[i] = (int)myList[i];
  Console.Write("{0} ", intArr[i]);
  Console.WriteLine();
}
posted @ 2017-03-20 12:04  帕丁顿熊  阅读(2936)  评论(0编辑  收藏  举报