将整个数组从一种方法传递到另一种方法



如何将数组从一种方法传递到另一种方法?同样在主要方法中,洗牌一些数组会收到一个错误,说这是零参数,但是我想在那里提出什么参数呢?一些示例代码非常感谢

  class Program
{
    static void Main(string[] args)
    {
       ShuffledSomeArray();
        DoSomethingWithArray();
        Console.ReadLine();
    }
     static string[] ShuffledSomeArray(string [] array)
    {
        array = new string[5] { "1", "2", "3", "4", "5" };
        Random rnd = new Random();
        for(int i = 4; i>=0; i--)
        {
            int shuffle = rnd.Next(0, i);
           string rndpick = array[shuffle];
           array[shuffle] = array[i];
                array[i] = rndpick;
            Console.Write(array[i]);
        }
    }
    static void DoSomethingWithArray()
    {
    }
}

类似的东西:

 class Program
{
    static void Main(string[] args)
    {
        string[] arr = new string[5] { "1", "2", "3", "4", "5" };
        string[] result = ShuffledSomeArray(arr);
        DoSomethingWithArray(result);
        Console.ReadLine();
    }
     static string[] ShuffledSomeArray(string [] array)
    {
        Random rnd = new Random();
        for(int i = 4; i>=0; i--)
        {
            int shuffle = rnd.Next(0, i);
           string rndpick = array[shuffle];
           array[shuffle] = array[i];
                array[i] = rndpick;
            Console.Write(array[i]);
        }
    }
    static void DoSomethingWithArray(string[] array)
    {
    }
}

相关内容

最新更新