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
*/

AlanRank #669 · 3.6K reputationPosted Dec 1, 2007, 2:51 AM EST
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.
Posted Dec 1, 2007, 4:01 AM EST
Thank you for the explanation, Alan.