Skip to content

Check if a multi-dimensional array is empty #94

Discussion options

You must be logged in to vote

Solved here: https://stackoverflow.com/a/68160416/8456445

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 exampl…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ChildishGiant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant