Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
A struct is used instead of a class when value-type semantics are desirable. Good examples are numeric types, where it is more natural for assignment to copy a value rather than a ref- erence. Because a struct is a value type, each instance does not require instantiation of an object on the heap; this can incur a useful saving when creating many instances of a type. For in- stance, creating an array of a value type requires only a single heap allocation. Struct Construction Semantics The construction semantics of a struct are as follows: · A parameterless constructor that you can't override im- plicitly exists. This performs a bitwise-zeroing of its fields. · When you define a struct constructor (with parameters), you must explicitly assign every field. · You can't have field initializers in a struct.