Hi Guys
NP66 GetLength(0) and Length
GetLength(0) and Length producing same results. I wish to know whether
These are same or different. Anyone knows please explain.
Thank you
using System;
class MainClass
{
static void
{
int[] arr = new int[] { 15, 20, 5, 25, 10 };
Console.WriteLine("GetLength(0) = {0}", arr.GetLength(0));
Console.WriteLine("Length = {0}", arr.Length);
}
}
/*
GetLength(0) = 5
Length = 5
*/
Posted Dec 1, 2007, 9:01 AM
Thank you for the explanation, Alan.
AlanPosted Dec 1, 2007, 7:51 AM
GetLength(0) returns the length of the first dimension of an array.
The Length property returns the total number of elements in all the dimensions of an array.
Thus, in the case of a single dimensional array, GetLength(0) returns the same value as Length.