Just a small C# Question

koeks525

Executive Member
Joined
Jul 14, 2012
Messages
6,011
Reaction score
1,197
Location
Canada
Hi guys,

I just would like to ask you all, with regards to C# 2D-Arrays, what is the difference between the GetLength(x) and GetLongLength(x)?

I'm currently trying to go through this one question where they asking us to do all sorts of things with this 2D array (work out min, max, average).

Thanks.
 
GetLength gets a 32 bit integer that represents the number of elemets in the array and getlonglength uses 64 bit to do the same thing.
 
Or in more technical terms:

public long GetLongLength(int dimension)
public int GetLength(int dimension)

So chances are if it's an array that contains more than 2^32 elements, you need to use GetLongLength() or else get an overflow error .
 
Last edited:
Hi guys,

I just would like to ask you all, with regards to C# 2D-Arrays, what is the difference between the GetLength(x) and GetLongLength(x)?

I'm currently trying to go through this one question where they asking us to do all sorts of things with this 2D array (work out min, max, average).

Thanks.

Out of curiosity. Do you not have access to MSDN?
 
I do have access to internet [could have just Google'd this ish], but I was too lazy to go through the results :D Since MyBB has got a number of Tech Geniuses, I thought to ask here :D

I used to be confused as to which to use: Array.GetLength(0) or Array.GetLength(1)
 
I do have access to internet [could have just Google'd this ish], but I was too lazy to go through the results :D Since MyBB has got a number of Tech Geniuses, I thought to ask here :D

I used to be confused as to which to use: Array.GetLength(0) or Array.GetLength(1)

The 0 and 1 are the dimensions aren't they?
 
I do have access to internet [could have just Google'd this ish], but I was too lazy to go through the results :D Since MyBB has got a number of Tech Geniuses, I thought to ask here :D

I used to be confused as to which to use: Array.GetLength(0) or Array.GetLength(1)

EDIT: Double post, delete this one please.
 
The 0 and 1 are the dimensions aren't they?

Yes, this gets used when dealing with a 2D Array. Basically the 0 is to work with the rows and the 1 is to work with the columns (as I understand it).
 
Yes, this gets used when dealing with a 2D Array. Basically the 0 is to work with the rows and the 1 is to work with the columns (as I understand it).

Obviously dimension n is referenced by [n-1].
 
I do have access to internet [could have just Google'd this ish], but I was too lazy to go through the results :D Since MyBB has got a number of Tech Geniuses, I thought to ask here :D

I used to be confused as to which to use: Array.GetLength(0) or Array.GetLength(1)

Totally acceptable :)
We all do it, it's what makes this place cool
 
I have no problem with that. But a developer needs to know how to read technical documentation. If clarification is needed, then ask.

But that's just me. :)

Actually Visual Studio's intellisense will explain the difference between GetLength and GetLongLength perfectly. Also the GetLength(dimension) function. It explains all overrides.
 
Top
Sign up to the MyBroadband newsletter
X