3.5. Types

The .NET Framework class library supports two groups of types:

  • value types;

  • reference types.

The major distinction between these two groups is that value types are allocated on the stack, while reference types are stored in the heap.

Value types cannot be null and must always contain data. That's why for each value type there is always a default value. Value types are always passed by value – that is, in our functions, we always deal with the copy of the value, leaving the original value unchanged. Most of the value types are not more than 12 to 16 bytes in size – as they are located in the stack, they should not consume much memory.

Reference types are used to represent data structures that may consume significant memory resources. ...

Get A Programmer's Guide to .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.