Arguments GetLength ()

What do GetLength Arguments mean? eg

value.GetLength(1) 

where the value is a two-dimensional array double [,] What will change to 0 and 1 in?

+4
source share
2 answers

The argument to GetLength determines the size. The method returns the number of elements in the specified dimension. Example with a two-dimensional array:

 class Program { static void Main() { var a = new int[5, 4]; Console.WriteLine(a.GetLength(0)); Console.WriteLine(a.GetLength(1)); } } 

prints 5 and 4 on the screen.

+3
source

GetLength(i) returns the number of elements in the i th dimension. Thus, for a two-dimensional array, GetLength(0) returns the number of rows, and GetLength(1) returns the number of columns.

+2
source

Source: https://habr.com/ru/post/1309872/


All Articles