Structures define value types. Variables of a value type store an actual value, as opposed to a reference to a value stored elsewhere. Contrast this with classes, which define reference types. Variables of a reference type store a reference (a pointer) to the actual value. See the discussion of value types versus reference types in Section 2.5 earlier in this chapter. Example 2-8 shows a structure definition.

Example 2-8. A structure definition

Public Structure Complex ' The IFormattable interface provides a generic mechanism for ' asking a value to represent itself as a string. Implements IFormattable ' These private members store the value of the complex number. Private m_RealPart As Double Private m_ImaginaryPart As Double ' These fields provide potentially useful values, similar to the ' corresponding values in the Double type. They are initialized ' in the shared constructor. The ReadOnly modifier indicates that ' they can be set only in a constructor. Public Shared ReadOnly MaxValue As Complex Public Shared ReadOnly MinValue As Complex ' This is a shared constructor. It is run once by the runtime ' before any other access to the Complex type occurs. Note again ' that this is run only once in the life of the program--not once ' for each instance. Note also that there is never an access ' modifier on shared constructors. Shared Sub New( ) MaxValue = New Complex(Double.MaxValue, Double.MaxValue) MinValue = New Complex(Double.MinValue, Double.MinValue) End Sub ' The ...

Get Programming Visual Basic .NET now with the O’Reilly learning platform.

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