O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Constructors and Default Instantiations of Value Types

Because no structure instances can exist without data, the CLR automatically creates a corresponding data instance when a structure is defined—regardless of whether New was used to instantiate the structure. The following example illustrates this point:

Dim AValue As NumberSystems
Dim AReference As ReferenceType

AValue.Value = 10
AReference.Value = 10

These lines execute with no problems until the last line, which triggers an exception because you are trying to change the property of an object that doesn’t exist on the Managed Heap, as illustrated in Figure 11-1.

Trying to change a property of an object that was not instantiated causes an exception.

Figure 11-1. Trying to change a ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required