为什么 ResizeArray 在我的代码中不起作用?

Why does ResizeArray not work in my code?

我的代码有问题:

namespace hello
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int xx = 5;
            string[,] myArray = new string[1, 5];
            if (xx > 4)
            {
                ResizeArray(ref myArray, 4, 5);
            }
            else
            {
                ResizeArray(ref myArray, 2, 5);
            }
        }
         void ResizeArray(ref string[,] original, int rows, int cols)
        {
            string[,] newArray = new string[rows, cols];
            Array.Copy(original, newArray, original.Length);
            original = newArray;
        }
    }
}

我收到错误消息:

An object reference is required for the non-static field, method, or property 'hello.Program.ResizeArray(ref string[,], int, int)'

静态成员在不创建实例的情况下无法访问 non-static 成员。 您只需要:

static void ResizeArray(ref string[,] original, int rows, int cols)