Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the UInt32 data type in Visual Basic .NET?

What is the UInt32 datatype in VB.NET?

Can someone inform me about its bit length and the differences between UInt32 and Int32? Is it an integer or floating point number?

like image 546
user156073 Avatar asked Oct 20 '25 05:10

user156073


2 Answers

It's an unsigned 32 bit integer:

  • U for unsigned
  • Int for integer
  • 32 for 32

Or you could just look at the documentation:

Represents a 32-bit unsigned integer.

like image 190
Jon Skeet Avatar answered Oct 21 '25 20:10

Jon Skeet


A UInt32 is an unsigned integer of 32 bits. A 32 bit integer is capable of holding values from -2,147,483,648 to 2,147,483,647.

However, as you have specified an unsigned integer it will only be capable of storing positive values. The range on an unsigned 32 bit integer is from 0 to 4,294,967,295.

Attempts to assign values to an Int or UInt outside of its range will result in an System.OverflowException.

Obviously, both UInt32 and Int32 are integers (not floating point), meaning no decimal portion is permitted or stored.

It may also be interesting to note that Integer and System.Int32 are the same in .NET.

For performance reasons you should always try to use Int32 for 32 bit processors and Int64 for 64 bit processors as loading these types to and from memory will be faster than other options.

Finally, try to avoid use of unsigned integers as they are not CLS compliant. If you need positive only integer that has the upper limit of the UInt32 it is better to use an Int64 instead. Unsigned integers are usually only used for API calls and the like.

like image 34
Sonny Boy Avatar answered Oct 21 '25 19:10

Sonny Boy