Numeric value of ULong.MaxValue is considered an overflow in Visual Basic.NET

666 Views Asked by At

In Visual Basic.NET ULong.MaxValue=18,446,744,073,709,551,615.

The following code runs fine:

Dim a As ULong = ULong.MaxValue

The following code returns an overflow error on the number

Dim b As ULong = 18446744073709551615

What is causing this error?

1

There are 1 best solutions below

0
On BEST ANSWER

The compiler assumes that any whole number too large to be an Integer is a Long and of course your number won't fit in a Long. You need to add the UL suffix to the literal number to indicate that it is ULong and not just Long.

Dim b As ULong = 18446744073709551615UL