C# Array LongLength
Description
Array LongLength
gets a 64-bit integer that represents
the total number of elements in all the dimensions of the Array.
Syntax
Array.LongLength
has the following syntax.
[ComVisibleAttribute(false)]
public long LongLength { get; }
Example
using System;/*from w ww . j a v a 2 s.c o m*/
public class MainClass
{
public static void Main(){
String[] array1d = { "zero", "one", "two", "three" };
ShowArrayInfo(array1d);
String[,] array2d= { { "zero", "0" }, { "one", "1" },
{ "two", "2" }, { "three", "3"},
{ "four", "4" }, { "five", "5" } };
ShowArrayInfo(array2d);
}
private static void ShowArrayInfo(Array arr)
{
Console.WriteLine("Length of Array: {0,3}", arr.LongLength);
Console.WriteLine("Number of Dimensions: {0,3}", arr.Rank);
if (arr.Rank > 1) {
for (int dimension = 1; dimension <= arr.Rank; dimension++)
Console.WriteLine(" Dimension {0}: {1,3}", dimension,
arr.GetUpperBound(dimension - 1) + 1);
}
Console.WriteLine();
}
}
The code above generates the following result.