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 26-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 26-5), and Type, which in turn represents compile-time type information about other types defined within the .NET environment (the type metadata). More on Type can be found in Chapter 35.
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 C# with keywords such as int, double, and bool. See the description of each type for more details. See also Section 2.5. 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.
Base types for delegate types (see Figure 26-2) created using the delegate keyword in C#.
The base type required for any type that wishes to be used as an attribute on other types, or methods, fields, etc. (see Figure 26-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 26-3 and Figure 26-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.