In VB.NET, we use various number types. Numbers are a foundational type throughout programs. And most commonly, we use Integer.
They are copied on assignment. Their data is stored (represented) within the variables themselves. And numbers do not use heap allocation like objects.
The Integer type is used throughout every program. Number types vary in size. Some use more memory—these represent larger, smaller or more detailed numbers.
Short
, Integer, Long—has a different maximum value. This is the highest value the type can represent.Short
, Integer and Long types.Module Module1 Sub Main() Dim a As Byte = Byte.MaxValue Dim b As Short = Short.MaxValue Dim c As Integer = Integer.MaxValue Dim d As Long = Long.MaxValue Console.WriteLine(a) Console.WriteLine(b) Console.WriteLine(c) Console.WriteLine(d) End Sub End Module255 32767 2147483647 9223372036854775807
There are unsigned types available. These omit the sign bit, so they can store a larger maximum value than the equivalent signed types.
MaxValue
of UInteger
, ULong
and UShort
. The maximum of ULong
is 20 digits.Module Module1 Sub Main() ' Demonstrate some unsigned types. Dim value1 As UInteger = UInteger.MaxValue Dim value2 As ULong = ULong.MaxValue Dim value3 As UShort = UShort.MaxValue Console.WriteLine(value1) Console.WriteLine(value2) Console.WriteLine(value3) End Sub End Module4294967295 18446744073709551615 65535
An Integer is four bytes. This is often the fastest type for local variables in methods. It does not handle decimal values. A double
is 8 bytes. A byte
is just one.
Decimal
type contains 16 bytes, making it four times the size of an Integer.Random
class
generates unpredictable integers. We optionally specify a minimum and maximum.A character is a value, similar to an Integer or UShort
. The Char
type represents a character. Certain functions such as Chr, Val and Asc also handle character values.
String
Class
extensively uses Char
values. Each String
internally contains Chars.A Boolean
value represents true or false, yes or no. It is represented by one byte
in this language. It can be used in an If
-statement or While
-loop.
This class
handles mathematical computations. It computes absolute values, maximums, minimums, square roots. The class
is reliable and tested.
Numbers like Integer are everywhere in VB.NET. With related types (Boolean
, Char
) we are also using numbers. Values may be modified and converted.