The runtime tries to calculate how much space is needed to store your array, and the first array is too large for the result to fit in the range of the type used.
The first array needs 0x40000000 * 4 = 0x0100000000 bytes of storage, while the second one needs only 0xc0000000 bytes.
Tweaking the array size and the array type (e.g. long[]
or char[]
) indicates that whenever the required space for the array goes over 0xffffffff you get the OverflowException
; otherwise, the runtime attempts to create the array and crashes.
Based on the above I think it's fairly safe to conclude that the required space is being calculated using a value of type uint
in a checked
context. If the calculation overflows you unsurprisingly get the OverflowException
; otherwise the runtime blows up due to the invalid unsafe operation.