Value Types

Value types are used for a single piece of information which is stored in an area called the Stack


bool (true or false)System.Boolean
(1 bit)
byte (unsigned Integer 0 to 255)Positive Integers up to 2^8-1, System.Byte
1 byte (8 bits)
char (0 to 65,536 different characters)System.Char
2 bytes (16 bits)
u 000 to u FFFF
decimal (1 E -28 to 7.9 E 28)Exact Precision Floating Point, System.Decimal
16 bytes (128 bits)
29 significant digits
Abbreviation Suffix - m or M (D in VB.Net)
Currency in VBA
double (-1.797 E 308 to 1.797 E 308)Double Precision Floating Point, System.Double
8 bytes (64 bits)
17 significant digits
Abbreviation Suffix - d or D (R in VB.Net)
float (-3.402 E 38 to 3.4.02 E 38)Single Precision Floating Point, System.Single
4 bytes (32 bits)
8 significant digits
Abbreviation Suffix - f or F
int (-2,147,483,648 to 2,147,483,647)Integer from -2^31 to 2^31-1, System.Int32
4 bytes (32 bits)
long (-9.2 E 18 to 9.2 E 18)Integer from -2^63 to 2^63-1 System.Int64
8 bytes (64 bits)
Abbreviation Suffix - l or L
sbyte (-128 to 127)Integer from -2^7 to 2^7-1, System.SByte
1 byte (8 bits)
short (-32,768 to 32,767)Integer from -2^15 to 2^15-1 System.Int16
2 bytes (16 bits)
Integer in VBA
single = float 
uint (unsigned Integer 0 to 4,294,967,295)Positive Integers up to 2^32-1, System.UInt32
4 bytes (32 bits)
Abbreviation Suffix - u or U
ulong (unsigned Integer 0 to 1.84 E 19)Positive Integers up to 2^64-1, System.UInt64
8 bytes (64 bits)
Abbreviation Suffix - ul or UL
ushort (unsigned Integer 0 to 65,535)Positive Integers up to 2^16-1, System.UInt16
2 bytes (16 bits)
bool (true or false)
System.Boolean
(1 bit)
byte (unsigned Integer 0 to 255)
Positive Integers up to 2^8-1, System.Byte
1 byte (8 bits)
char (0 to 65,536 different characters)
System.Char
2 bytes (16 bits)
u 000 to u FFFF
decimal (1 E -28 to 7.9 E 28)
Exact Precision Floating Point, System.Decimal
16 bytes (128 bits)
29 significant digits
Abbreviation Suffix - m or M (D in VB.Net)
Currency in VBA
double (-1.797 E 308 to 1.797 E 308)
Double Precision Floating Point, System.Double
8 bytes (64 bits)
17 significant digits
Abbreviation Suffix - d or D (R in VB.Net)
float (-3.402 E 38 to 3.4.02 E 38)
Single Precision Floating Point, System.Single
4 bytes (32 bits)
8 significant digits
Abbreviation Suffix - f or F
int (-2,147,483,648 to 2,147,483,647)
Integer from -2^31 to 2^31-1, System.Int32
4 bytes (32 bits)
long (-9.2 E 18 to 9.2 E 18)
Integer from -2^63 to 2^63-1 System.Int64
8 bytes (64 bits)
Abbreviation Suffix - l or L
sbyte (-128 to 127)
Integer from -2^7 to 2^7-1, System.SByte
1 byte (8 bits)
short (-32,768 to 32,767)
Integer from -2^15 to 2^15-1 System.Int16
2 bytes (16 bits)
Integer in VBA
single = float
uint (unsigned Integer 0 to 4,294,967,295)
Positive Integers up to 2^32-1, System.UInt32
4 bytes (32 bits)
Abbreviation Suffix - u or U
ulong (unsigned Integer 0 to 1.84 E 19)
Positive Integers up to 2^64-1, System.UInt64
8 bytes (64 bits)
Abbreviation Suffix - ul or UL
ushort (unsigned Integer 0 to 65,535)
Positive Integers up to 2^16-1, System.UInt16
2 bytes (16 bits)




There are two fundamental building blocks of .NET types. The class and the value type
Assigning one value type variable to another copies the contained value.


These are passed by value and a copy of the variable is made.
User defined structs are value types
This is a fixed amount of memory.


Classes are known as reference types because you always access objects by using reference variables.
A reference variable lets us refer to an object created by the "New" operator.
Accessing objects in this way allows the .NET garbage collection mechanism to reclaim the resources used by an object when no body has a reference to it anymore.
This feature makes for efficient memory usage and eliminates the possibility of memory leaks


All operations on objects are done by calling member functions, using the -> operator.
Value types hold values (integers, floating point numbers etc), anything that is basically a wrapper around a simple value and is less than about 16 bytes in size.
We need value types as we want simple values to be used as efficiently as possible.


.NET gets around this problem by using Value types. These value types are represented and used efficiently as built-in types, which can also be used as objects when necessary (often refered to as boxing)
There are performance issues to consider when using reference types. Reference types have to be accessed via their pointers, affecting both the size and speed of the compiled application.


A Value type is a type that inherits from the System::ValueType class. Value types have several special properties:


  • Value types are stored on the stack (unlike references which are stored on the run-time heap)

  • Instances of value types are always accessed directly (unlike reference types which are accessed through references) This means that you don't use the "New" operator whne creating instances

  • Copying value types copies the value rather than the reference


The important difference between structures and classes is that structures are value types. This means that if you have a value type that needs to have some internal structure you can implement is using a "Struct"


Integers range from four to eight bytes
You can know loop through 1 to 65,000 rows in Excel using an Integer


The Currency value type (previously eight bytes) has been replaced with the more capable Decimal (12 bytes)
This is used when you have large numbers that you do not want rounded internally (which single and double do)



The Value Variant type in VBA has been replaced with the Object reference type






© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext