The confusion for me here is C-Sharp does not seem to complain. VB being
simple enough why is there this problem? Maybe they have not changed the
underlying type from VB??
It would appear this is one the very few times when VB.NET is stricter
than C#. To wit, and to recap for C#ers just joining us:
C#
int[] f = new int[3000000000];
// compiles, throws System.OverflowException at run time
VB.NET
Dim f(3000000000) As Integer
' Will not compile: error is 'Constant expression not representable in
type Integer'
So here, the VB.NET compiler can work out at compile time that 3
billion is bigger than an Int32, and thus can't be used as an array
size (a CLS limitation I would suspect); but the C# compiler can't, or
doesn't care.
Your particular example can be examined also:
C#
long l = 3000000000;
int[] f = new int[l];
// compiles, throws System.OverflowException at run time
VB.NET
Dim l As Long = 3000000000
Dim f(l) As Integer
' Will not compile under Option Strict On:
' error is 'Option Strict On disallows implicit conversions from
'<type1>' to '<type2>''
' WILL compile with Option Strict Off: throws System.OverflowException
at run time
So for me the question is, why does C# allow this unstated cast from
long to int to compile? To that end I have xposted to the C# group