In C#, GetLongLength(dimension) is like GetLength, but it returns a long instead of an int.
Everyday arrays fit in int. Use GetLongLength when you must handle enormous dimensions safely as 64-bit values.
This is an instance member of System.Array. You call it on an array variable with a dot, such as arr.GetLongLength(...). Arrays in C# have a fixed length after creation; use List<T> when the count must grow.
Syntax
Call GetLongLength with a 0-based dimension index.
C#
long rows = grid.GetLongLength(0);
Call
What it does
grid.GetLongLength(0)
Dimension 0 length as long.
grid.GetLongLength(1)
Dimension 1 length as long.
For most beginner programs, prefer GetLength.
Library declarations
C#
public long GetLongLength(int dimension);
Parameters
Parameter
Description
dimension
Required. 0-based dimension index.
Return Value
Return Value
Description
long
Length of that dimension.
C# Examples
Example 1 — Long Length of a Dimension
Print GetLongLength beside GetLength.
C#
using System;
class Program {
static void Main() {
int[,] grid = new int[2, 4];
Console.WriteLine(grid.GetLongLength(0));
Console.WriteLine(grid.GetLongLength(1));
Console.WriteLine(grid.GetLength(1));
}
}
Output
2
4
4
How It Works
Same counts. 2 and 4 match the int API.
long type. Useful when assigning to long variables.
GetLength agrees. Dimension 1 is 4 either way.
Small grid. No overflow concerns here.
Example 2 — 1D Array GetLongLength
Compare with Length on a vector.
C#
using System;
class Program {
static void Main() {
string[] names = { "a", "b", "c" };
long n = names.GetLongLength(0);
Console.WriteLine(n);
Console.WriteLine(n == names.Length);
}
}
Output
3
True
How It Works
Dimension 0. Only dimension on a 1D array.
Value 3. Three names.
Equals Length. Comparison to int Length is true after numeric promotion.
Beginner default. Still prefer Length for 1D.
Example 3 — Loop Using GetLongLength
Use long indexes carefully (shown with cast for indexer).
C#
using System;
class Program {
static void Main() {
int[] nums = { 10, 20, 30 };
long len = nums.GetLongLength(0);
for (long i = 0; i < len; i++) {
Console.WriteLine(nums[(int)i]);
}
}
}
Output
10
20
30
How It Works
long loop var. Matches GetLongLength’s return type.
Cast for indexer. Typical int[] indexer wants int.
Same visit order. All three values print.
Rare need. Shown for API completeness.
Frequently Asked Questions
When a dimension might be larger than int can store, or when you already work in long sizes.
The numeric value matches; only the return type differs (long vs int).
Yes. Pass the dimension index like GetLength.
An int total element count. Huge arrays also have LongLength.