5

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?

Ahmad Farid
  • 14,398
  • 45
  • 96
  • 136
  • It means nothing as there's no such method in the BCL. If this is a standard method provide a link on MSDN to the documentation to remove any ambiguity and if it is your own extension method, please provide source code for it. – Darin Dimitrov May 15 '10 at 18:38
  • What `GetSize` are you talking about? Where is it found? – Oded May 15 '10 at 18:39
  • Am I correct in deducing from the `()(1)` that this Getsize is a nullary function returning a unary function? Strange. – sepp2k May 15 '10 at 18:41
  • oh sorry! I meant GetLength(1) – Ahmad Farid May 15 '10 at 18:42
  • Also see http://stackoverflow.com/questions/677909/double-type-how-to-get-the-of-rows/677955#677955 – H H May 15 '10 at 20:26

2 Answers2

4

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.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • This doesn't make any sense. To me, this looks like you just returned the value in position 0 and the value at position 1. – Neo42 Sep 25 '17 at 13:11
2

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.

sepp2k
  • 363,768
  • 54
  • 674
  • 675