Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does assigning 0xFFFFFFFF to a UInteger generate an error in VB.NET?

Tags:

A UInteger data type holds any value between 0 and 4,294,967,295 (ref. MSDN).

If I try this code in VB.NET, I get a compiler error:

Dim Test As UInteger = &HFFFFFFFF 

Error: "Constant expression not representable in type 'UInteger'.

Why I can't set 0xFFFFFFFF (4,294,967,295) to a UInteger if this type can hold this value?

like image 291
RHaguiuda Avatar asked Sep 01 '10 18:09

RHaguiuda


2 Answers

I believe it's because the literal &HFFFFFFFF is interpreted by the VB.NET compiler as an Integer, and that value for an Integer is a negative number (-1), which obviously can't be cast to a UInteger.

This issue is easily fixed by writing &HFFFFFFFFUI, appending the UI suffix to treat the literal as a UInteger.

like image 155
Dan Tao Avatar answered Sep 22 '22 02:09

Dan Tao


You could use the MaxValue constant:

Dim Test As UInteger = UInteger.MaxValue 
like image 24
Darin Dimitrov Avatar answered Sep 20 '22 02:09

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!