How can I determine the size (length / number of objects) in an array in C #?
If this is a one-dimensional array a ,
a.Length a will be given.
If b is a rectangular multi-dimensional array (for example, int [,] b = new int [3, 5]; )
b.Rank will give the dimension (2) and
b.GetLength (dimension index) Length of a given dimension (for 0-based indexing dimensions - hence the b.getLength (0) 3 and b.GetLength (1 ) is 5).
See for more information.
As stated in the comment by @Lioro, there is a concept of "jagged array", which is actually nothing more than a one-dimensional array (usually single-dimensional) arrays.
For example, this could be:
int [] [] c = new int [3] []; C [0] = new int [] {1, 2, 3}; C [1] = new int [] (3, 14}; c [2] = new int [] (1, 1, 2, 3, 5, 8, 13}; c have different lengths, in this case, c as before c.Length (3) and c [0]. The length of , c [1]. Lambon , and c [2]. Will be 3, 2 and 7, respectively.
Comments
Post a Comment