0x80000000 == 2147483648 in C# but not in VB.NET

.net, c#, hex, vb.net

Solution

This is related to the history behind the languages.

C# always supported unsigned integers. The value you use are too large for int so the compiler picks the next type that can correctly represent the value. Which is uint for both.

VB.NET didn't acquire unsigned integer support until version 8 (.NET 2.0). So traditionally, the compiler was forced to pick Long as the type for the 2147483648 literal. The rule was however different for the hexadecimal literal, it traditionally supported specifying the bit pattern of a negative value (see section 2.4.2 in the language spec). So &H80000000 is a literal of type Integer with the value -2147483648 and 2147483648 is a Long. Thus the mismatch.

If you think VB.NET is a quirky language then I'd invite you to read this post :)

Problem

In C#: ``` 0x80000000==2147483648 //outputs True ``` In VB.NET: ``` &H80000000=2147483648 'outputs False ``` How is this possible?

Original source

Related problems