Miko Kronn
Miko Kronn

Reputation: 2454

How to check sizes of two (or more) dimensional array in C#?

I have:

double[,] table = new double[3,4];

How to check both sizes of that table? table.Length gives me 12 which is total number of elements in table.

Upvotes: 3

Views: 171

Answers (3)

Øyvind Bråthen
Øyvind Bråthen

Reputation: 60694

Use the GetLength method.

So table.GetLength(0) will return 3 and table.GetLength(1) will return 4.

The parameter for GetLength is the zero-based dimension of the array you want to know the length of.

Upvotes: 8

Tommy
Tommy

Reputation: 1985

GetLength?

ref

Upvotes: 1

Saif al Harthi
Saif al Harthi

Reputation: 2974

Table.GetLength(0); gives you 3

Table.GetLength(1); gives you 4

Hope this helps.

Upvotes: 5

Related Questions