.Length compared to .LongLength when the size of the array is larger than Int32.MaxValue

I am looking for documentation about the differences between .Length and .LongLength array properties.

In particular, if the length of the array is greater than Int32.MaxValue, will .Length throw an exception, return Int32.MaxValue, go negative, return 0?

(to fix the “possible recurring” problems: I am not asking about the maximum length of the array or the maximum size of the CLR.NET object. Suppose that there is a 64-bit system and a version of the CLR that supports large objects)

+6
source share
1 answer

It is impossible to create a one-dimensional array having more than 2,147,483,591 elements (for comparison, int.MaxValue is 2,147,483,647). OutOfMemoryException is OutOfMemoryException if an attempt is made to create an array with a large number of elements. This means that the LongLength property is still useless, and you can use the Length property instead .

I tested it on x64 platform using .NET 4.5. To create an array with 2,147,483,591 elements, I changed the configuration file and added:

 <configuration> <runtime> <gcAllowVeryLargeObjects enabled="true" /> </runtime> </configuration> 

I mainly used this page

+7
source

All Articles