Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arguments of GetLength()

Tags:

c#

What does the Arguments of GetLength mean? for example

value.GetLength(1)

where value is a two dimensional Array double[,] What will changing 0 and 1 differ in?

like image 754
Ahmad Farid Avatar asked May 15 '10 18:05

Ahmad Farid


People also ask

What is GetLength?

The GETLENGTH function returns the length of a large object. The function returns an INTEGER value that reflects the length of the large object in bytes (for a BLOB) or characters (for a CLOB).

How do you use GetLength?

GetLength(Int32) Method is used to find the total number of elements present in the specified dimension of the Array. Syntax: public int GetLength (int dimension); Here, dimension is a zero-based dimension of the Array whose length needs to be determined.

What is the difference between. length and. GetLength?

GetLength returns the length of a specified dimension of a mulit-dimensional array. Length returns the sum of the total number of elements in all the dimensions.

What does GetLength 0 mean?

An example of GetLength is GetLength(0) , which returns the number of elements in the first dimension of the Array.


2 Answers

The argument for GetLength method specifies the dimension. 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.

like image 199
Darin Dimitrov Avatar answered Sep 28 '22 08:09

Darin Dimitrov


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

like image 42
sepp2k Avatar answered Sep 28 '22 09:09

sepp2k