CHAPTER 3 CORE C# PROGRAMMING CONSTRUCTS, PART I
Figure 3-2. The class hierarchy of system types
Notice that each of these types ultimately derive from System.Object, which defines a set of
methods (e.g., ToString(), Equals(), GetHashCode()) common to all types in the .NET base class libraries
(these methods are fully detailed in Chapter 6).
Also note that many numerical data types derive from a class named System.ValueType.
Descendents of ValueType are automatically allocated on the stack and, therefore, have a very
predictable lifetime and are quite efficient. On the other hand, types that do not have System.ValueType
in their inheritance chain (such as System.Type, System.String, System.Array, System.Exception, and
System.Delegate) are not allocated on the stack, but on the garbage-collected heap. (More information
on this distinction can be found in Chapter 4.)
Without getting too hung up on the details of System.Object and System.ValueType, just understand
that because a C# keyword (such as int) is simply shorthand notation for the corresponding system type
(in this case, System.Int32), the following is perfectly legal syntax, given that System.Int32 (the C# int)
eventually derives from System.Object and, therefore, can invoke any of its public members, as
illustrated by this additional helper function:
90