Difference between [,] array and [][] array

Hi everyone,
if I recall correctly, C# uses [,] for 2dimensional arrays.
I think I tried [ ][ ] in previous unity versions and didn’t work, so thats when I read about that in C# you declare it with [,].

However, recently I just created a 2dim.array with [ ][ ] and it totally worked.
(I don’t know if I just made a typo in the past, or if it really was not possible).

My question now is, what is the difference betweens these two?
Is it only that I can declare the length with [ ][ ] later?

And are there any reasons why using the one over the other.
E.g. faster proccessing, etc.

See multidimensional array:

vs
“jagged array”:

With the regular multidimensional array, you instantiate it once, and it’s always perfectly rectangular (each subarray is the same length).
With the jagged array you need to individually instantiate each “sub-array” because they don’t have to be the same length.

The regular multidimensional array (the one with [,]) is pretty much just slightly easier to instantiate. I think under the hood the performance will be roughly the same, though I wouldn’t be surprised if there are some compiler optimizations that might improve the performance somewhat. The jagged array may have some more overhead since each array is its own object So basically if all of your subarrays are the same length go ahead and use the multidimensional array. Otherwise you have to use a “jagged array”.

OK, checked the docs, thanks.

One more question, how can I get the Length of a multidimensional array?
Let’s say I have

int[,] rnd = new int[3, 5];

using

Debug.Log(rnd.Length);

gives me the whole length (15).
How can I access the Length of 3 and 5?

Use this method: Array.GetLength(Int32) Method (System) | Microsoft Learn

for example:

int firstDimensionLength = rnd.GetLength(0);
int secondDimensionLength = rnd.GetLength(1);