tags:

views:

136

answers:

3

Hi,

I seem to be getting an odd value.

How do I get the number of rows in my array:

double[,] lookup = { {1,2,3}, {4,5,6} };

The output should be 2.

+2  A: 

You want the rank property on the array...

double[,] lookup = { { 1, 2, 3 }, { 4, 5, 6 } };
Console.WriteLine(lookup.Rank);

This will provide you with the number of dimensions.

Edit:
This will only provide you with the number of dimensions for the array as opposed to the number of primary elements or "rows" see @Henk Holterman's answer for a working solution.

Quintin Robinson
but not the number of rows. See @Henk Holterman's answer for more details.
Blair Conrad
@Blair indeed I did misread.
Quintin Robinson
+11  A: 

lookup has two dimensions, this is how you read them

double[,] lookup = { {1,2,3}, {4,5,6} };

int rows = lookup.GetLength(0); // 2
int cols = lookup.GetLength(1); // 3    
int cells = lookup.Length; // 2*3 = 6

The rows and cols concept is just tradition, you could just as well call the first dimension the columns.

Also see this question

Henk Holterman
+1  A: 

I think what you're looking for is:

lookup.GetLength(0);
BFree