Each of these logically represent a single value, are a fixed size in memory of 16 bytes or less, are kept on the high-performance stack, and the assignment of the value to another variable makes another copy of the data.
A very useful extension of the value type is the known as a Structure (VB.Net) or struct (C#). These are essentially custom classes that, like all classes, can have constructors (the new operator), public/private properties, and public/private methods. The private variables within the structure must consist solely of value types and not exceed 16 bytes total in size.
Like primitive value types, structures logically represent a single value, are a fixed size in memory of 16 bytes or less, are kept on the high-performance stack, and the assignment of the value to another variable makes another copy of the data.
Structures allow you to create high-performance single-value custom data types with custom behaviors and characteristics enforced by its methods and properties. Structures can be combined in a [reference type] custom class to create a rich application object.
For example, an Employee class might contain a structure for Age that enforces a minimum value of zero and maximum value of 100, a structure for zip code that enforces a valid U.S. zip code, a structure for email that enforces a properly formatted email address, etc. You may wish to create a library of common structures to be used by multiple applications.
Finally, below is an source code example of a simple structure, a more complex structure, and and example of using them both. The source code is presented in both C# and VB.Net.
Click here to view C# Struct Code:
Click here to view the C# Code to use the struct:
Click here to view the VB.Net Structure Code:
Click here to view theVB.Net Code to use the structure: