To know the size of one vector, I can only use the
nomedovetor.Length
, right?
Depends, if it’s a array multidimensional the Array.GetLength()
should be more appropriate, it takes as argument the dimension of array, and will return the amount of such elements array, the Array.Length
will return all elements of all arrays.
Could you explain this to me 0 and 1 in brackets?
These values indicate the size of the array that you want to get the length,
Array.GetLength(0)
is the same as Array.Length
, when applied in a array of one dimension.
See a comparison between the two:
string[,] matriz = new string[,]{
{"1.1", "1.2", "1.3"},
{"2.1", "2.2", "2.3"},
{"3.1", "3.2", "3.3"}
};
Console.WriteLine(String.Format("Length: {0}", matriz.Length)); // 9
Console.WriteLine(String.Format("GetLength: {0}", matriz.GetLength(0))); // 3
See demonstração