我试图编写一个随机字符串数组算法,但我得到一个空引用错误..我不知道为什么..
public static string[] arrRandomized;
public static string[] ShuffleWords(string[] Words)
{
Random generator = new Random();
for (int i=0;i < Words.Length; i++) {
int pos = generator.Next(Words.Length);
Console.WriteLine(Words[pos]); // I SEE RANDOM ITEM
Console.Read(); // NULL REFERENCE ERROR AFTER THIS
if (Words[pos] != null)
{
arrRandomized[i] = Words[pos];
//remove item at pos so I get no duplicates
Words[pos] = null;
}
}
我不想使用 ArrayList,我有我的理由,但那是题外话我只想知道这怎么不起作用:/ 谢谢