O'Reilly logo

Professional Visual Basic 2012 and .NET 4.5 Programming by Todd Herman, Gastón Hillar, David McCarter, Rob Windsor, Billy Hollis, Bill Sheldon

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

Reference Types (Classes)

A lot of the power of Visual Basic is harnessed in objects. An object is defined by its class, which describes what data, methods, and other attributes an instance of that class supports. Thousands of classes are provided in the .NET Framework class library.

When code instantiates an object from a class, the object created is a reference type. Recall that the data contained in value and reference types is stored in different locations, but this is not the only difference between them. A class (which is the typical way to refer to a reference type) has additional capabilities, such as support for protected methods and properties, enhanced event-handling capabilities, constructors, and finalizers; and it can be extended with a custom base class via inheritance. Classes can also be used to define how operators such as “=” and “+” work on an instance of the class.

The intention of this section is to introduce you to some commonly used classes, and to complement your knowledge of the common value types already covered. This section examines the features of the Object, String, DBNull, and Array classes, as well as briefly introduce the Collection classes found in the System.Collections namespace.

The Object Class

As noted earlier, the Object class is the base class for every type in .NET, both value and reference types. At its core, every variable is an object and can be treated as such.

Because the Object class is the basis of all types, you can cast any variable ...

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