A Short value is limited to the maximum value that can be stored in two bytes. This means there are 16 bits and the value can range between -32768 and 32767. This limitation may or may not be based on the amount of memory physically associated with the value; it is a definition of what must occur in the .NET Framework. This is important, because there is no guarantee that the implementation will actually use less memory than when using an Integer value. It is possible that in order to optimize memory or processing, the operating system will allocate the same amount of physical memory used for an Integer type and then just limit the possible values.

The Short (or Int16) value type can be used to map SQL smallint values. Integer

An Integer is defined as a value that can be safely stored and transported in four bytes (not as a four-byte implementation). This gives the Integer and Int32 value types a range from -2147483648 to 2147483647. This range is more than adequate to handle most tasks.

The main reason to use an Int32 in place of an Integer value is to ensure future portability with interfaces. For example, the Integer value in Visual Basic 6.0 was limited to a two-byte value, but is now a four-byte value. In future 64-bit platforms, the Integer value might be an eight-byte value. Problems could occur if an interface used a 64-bit Integer with an interface that expected a 32-bit Integer value, or, conversely, if code using the Integer type is suddenly passed to a variable explicitly declared as Int32.

The solution is to be consistent. Use Int32, which would remain a 32-bit value, even on a 64-bit platform, if that is what you need. In addition, as a best practice, use Integer so your code is not constrained by the underlying implementation.

The Visual Basic .NET Integer value type matches the size of an Integer value in SQL Server, which means that you can easily align the column type of a table with the variable type in your programs.


The Long type is aligned with the Int64 value. The Long has an eight-byte range, which means that its value can range from -9223372036854775808 to 9223372036854775807. This is a big range, but if you need to add or multiply Integer values, then you need a large value to contain the result. It's common while doing math operations on one type of integer to use a larger type to capture the result if there's a chance that the result could exceed the limit of the types being manipulated.

The Long value type matches the bigint type in SQL.

Was this article helpful?

0 0

Post a comment