I have a really dumb question. Please forgive it’s late and I am tired. 🙂
I have a 2d array of ints defined as follows:
int[,] myArray = new int[,] // array of 7 int[,] arrays
{
{ 1, 10 }, // 0
{ 2, 20 }, // 1
{ 3, 30 }, // 2
{ 4, 40 }, // 3
{ 5, 50 }, // 4
{ 6, 60 }, // 5
{ 7, 70 }, // 6
};
As you can see the array consists of 7 int[,] arrays.
When I call myArray.Length it results in 14. What I need is 7. How do I get the number of int[,] arrays? What is the method to call (the result I am expecting is 7).
Thanks again!
That is not an array of 2D arrays – it is a single 2D array. As already noted, the dimensions are given by
myArray.GetLength(dimension). It is not an array with “7 int[,] arrays” – it is simply a 7-by-2 array.If you want an array of arrays (actually, a vector of vectors), it is:
and then the
7ismyArray.Length.