If I have an array like string[,] empty = {{}};
and check its length I get an int[]
. If I try to apps.length.length
it seems to work until I compare or print it when I then get unsupported use of length field of multi-dimensional array
. So I have no clue how to just check if there's any items in this array.
Multi dimensional arrays in vala are not arrays of arrays. For example this would be a compiler error:
int[,] d = {{2, 4, 6, 8},
{3, 5, 7, 9, 15},
{1, 3, 5, 7}};
The compiler expects 4 elements, but in the second intializer 5 elements are given.
The length method for a multi dimensional array will give you the size of the dimensions:
string[,] arr = {{}};
int len1 = arr.length[0];
int len2 = arr.length[1];
stdout.printf(@"$len1, $len2\n");
This outputs 1, 0 because the two dimesional array extends one element in the first dimension and zero elements in the second dimension.
So in the above example the array is not empty. It contains 1 row with 0 columns. You can add additional rows, but those also have to have 0 columns.