How to Set a Multidimensional Array Length

I have the following code:

public int lengthInt;
public int[, ] data = new int[0, 0];

void Start(){
     data.Length(0) = lengthInt;     //error
     data.Length(1) = lengthInt;     //error
}

From what I understand you can’t just have:

public int lengthInt;
public int[, ] data = new int[lengthInt, lengthInt];

You have to define the array length in a runtime function. However if I just had:

public int lengthInt;

void Start(){
     public int[, ] data = new int[lengthInt, lengthInt];
}

That would work but then it doesn’t show up in the inspector. So how do I set a multidimensional array length and have it visible in the inspector?

Thanks!

The problem is that `lengthInt == null` in your first try. If you assign a value to `lengthInt`, before you define the array it will work.

Your first example should become:

public static int lengthInt = 0;
public int[, ] data = new int[lengthInt, lengthInt];

The static tag however, will make that your class can only have one instance.

And arrays are never visible in the inspector by the way.