Skip to Content
Programming Visual Basic .NET
book

Programming Visual Basic .NET

by Dave Grundgeiger
December 2001
Beginner
464 pages
13h 51m
English
O'Reilly Media, Inc.
Content preview from Programming Visual Basic .NET

Structures

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Visual Basic .NET, Second Edition

Programming Visual Basic .NET, Second Edition

Jesse Liberty

Publisher Resources

ISBN: 0596000936Supplemental ContentCatalog PageErrata