由於某種原因,這不會編輯輸入到其中的數組的大小,並且數據不會添加到輸入的數組中。數組值不變?
public static void RandomizeArray(int[] array)
{
int intRead;
int intReadSeed;
Random randomNum = new Random();
Console.WriteLine("How many ints do you want to randomly generated?");
intRead = Convert.ToInt32(Console.ReadLine());
array = new int[intRead];
Console.WriteLine("What's the maximum value of the randomly generated ints?");
intReadSeed = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < intRead; i++)
{
array[i] = (randomNum.Next(intReadSeed));
}
Console.WriteLine("Randomization Complete.\n");
}
注意:您應該使用'randomNum.Next(intReadSeed + 1)',否則最大值將小於'intReadSeed'。 – Guffa 2013-03-28 01:53:34