[Previous] [Contents] [Next]

Value Types


When you have a variable that is a value type, you have a variable that contains actual data. Thus, the first rule of value types is that they cannot be null. For example, below I have allocated memory by creating a variable of the CTS type System.Int32 in C#. In this declaration, what happens is that a 32-bit space is allocated on the stack.

int i = 32;

In addition, the act of assigning a value to i results in that 32-bit value being moved into this allocated space.

There are several value types defined in C#, including enumerators, structures, and primitives. Anytime you declare a variable of one of these types, you have allocated the number of bytes associated with that type on the stack and are working directly with that allocated array of bits. In addition, when you pass a variable that is a value type, you're passing that variable's value and not a reference to its underlying object.

[Previous] [Contents] [Next]