面试题:C#声明一个100大小的数组 随机生成1-100之间不重复的数
下面是C#的实现方式,编译测试通过
public static void InsertRandomArray() { int[] intArray = new int[100]; ArrayList newArray = new ArrayList(); Random rnd = new Random(); while (newArray.Count < 100) { int tempNumber = rnd.Next(1, 101); if (!newArray.Contains(tempNumber)) newArray.Add(tempNumber); } for (int i = 0; i < 100; i++) { intArray[i] = (int)newArray[i]; Console.Write("{0},", intArray[i]); } }