Upper Lower Bounds
.Length
This property returns the number of elements in the array.
.GetLength
This method returns the number of elements in a particular dimension of the multi-dimensional array
int[,,] myArray = new int[5,6,7];
Console.WriteLine(myArray.Length); // 201, 5x6x7
Console.WriteLine(myArray.GetLength(0)); // 5
Console.WriteLine(myArray.GetLength(1)); // 6
Console.WriteLine(myArray.GetLength(2)); // 7
For a 1-dimensional array: Length and GetLength(0) are exactly the same.
For multi-dimensional arrays: Length is the product of all the dimensions
Length = GetLength(0) x ... x GetLength(Rank - 1)
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext