O'Reilly logo

VB.NET Core Classes in a Nutshell by Ted Neward, Budi Kurniawan

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

Chapter 4. System

In many respects, the System namespace serves as the core namespace for the .NET libraries, in much the same way java.lang does for Java programmers or stdlib.h does for C/C++ programmers. For example, the ECMA-compliant primitive-type value types are defined in the System namespace, along with complementary composite types and base types. These are used in the synthesis of type generation, which is done by the compiler on the .NET programmer’s behalf (for an example of this on-the-fly type synthesis, see Array). Figure 4-1 shows many of the types in this namespace.

System serves as the home for key base-type definitions, including Object, the root of every type in the .NET hierarchy. Every type in the system ultimately extends this class, making it the “root of all evil” in .NET. In addition, this namespace contains ValueType, the base type for all value types in .NET (such as the primitive types listed later in this chapter, shown in Figure 4-5), and Type, which in turn represents compile-time type information about other types defined within the .NET environment (the type metadata).

ECMA-compliant primitive-type value types include the fundamental types used for all .NET applications, which are basic value types such as Int32, Single, Double, Decimal, Char, Byte, and Boolean. All of the primitive types are aliased in VB.NET with keywords such as Integer, Double, and Boolean. See the description of each type for more details. In addition to these fundamental types, there are composite types such as DateTime and TimeSpan, used to handle date- and time-based calculations without having to drop down to integer math, and Uri, used to represent references to a Universal Resource Identifier, which is the more generic form of the ubiquitous HTTP URL identifier used on the Web.

In addition to these primitive and composite types, several interfaces defined here are intended as support interfaces. For example, the interfaces IConvertible, IComparable, and ICloneable let types support the same basic operations (conversion, comparison, and cloning, respectively) that the primitive types offer.

Along with the base types described earlier, System contains base types that programmers do not directly reference, such as the following:


The base type for any array-type declaration, allowing .NET developers to refer to any type (or rank) array without having to specify exact type.

System.Delegate and System.MulticastDelegate

Base types for delegate types (see Figure 4-2) created using the Delegate keyword in VB.NET.


The base type required for any type that wishes to be used as an attribute on other types, or methods, fields, etc. (see Figure 4-2).

Because delegates are often used in conjunction with events and event handlers, System also contains the definitions for EventHandler, the universal delegate type, and EventArgs, the base type representing data sent as part of an event-handler call.

System also serves as the heart of the exception-handling hierarchy in .NET, defining the base type Exception, which is the base type for all exceptions. The exception hierarchy is then bifurcated into two realms: system exceptions, which are exceptions generated by or relating to the runtime itself, and application exceptions, which are exceptions relating to the target business domain and typically are used on a per-application basis. SystemException serves as the base type for the former, and ApplicationException is the base type for the latter. Figure 4-3 and Figure 4-4 show the exceptions in the System namespace.

System also contains two definitions of some importance to the .NET programmer: the IDisposable interface, used to help programmers define cleanup and resource-release semantics for their types, and the GC class, which gives the .NET programmer access to the CLR garbage collector.

The System namespace also contains a few interoperability types. Guid represents the OSF UUID type that was made famous by COM. The attributes STAThreadAttribute and MTAThreadAttribute indicate to the runtime which sort of COM apartment-threading model the .NET component should use (but only when COM interoperability comes into play).

Finally, System defines the fundamental types such as Console and Environment. These give the .NET programmer access to the standard-in/standard-out streams (i.e., the command-shell console) and the environment variables of a given process, respectively. Most .NET applications will use ASP.NET or Windows Forms to present a graphical user interface. However, applications such as compilation tools, XML filters, and batch jobs use console I/O and environment variables extensively.

The System namespace

Figure 4-1. The System namespace

Attributes and delegates in the System namespace

Figure 4-2. Attributes and delegates in the System namespace

Exceptions in the System namespace

Figure 4-3. Exceptions in the System namespace

Specialized exceptions in the System namespace

Figure 4-4. Specialized exceptions in the System namespace

Value types in the System namespace

Figure 4-5. Value types in the System namespace

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