CHAPTER 1 THE PHILOSOPHY OF .NET
Understanding the Common Type System
A given assembly may contain any number of distinct types. In the world of .NET, type is simply a
general term used to refer to a member from the set {class, interface, structure, enumeration, delegate}.
When you build solutions using a .NET-aware language, you will most likely interact with many of these
types. For example, your assembly might define a single class that implements some number of
interfaces. Perhaps one of the interface methods takes an enumeration type as an input parameter and
returns a structure to the caller.
Recall that the CTS is a formal specification that documents how types must be defined in order to
be hosted by the CLR. Typically, the only individuals who are deeply concerned with the inner workings
of the CTS are those building tools and/or compilers that target the .NET platform. It is important,
however, for all .NET programmers to learn about how to work with the five types defined by the CTS in
their language of choice. Following is a brief overview.
CTS Class Types
Every .NET-aware language supports, at the very least, the notion of a class type, which is the
cornerstone of OOP (Object Oriented Programming). A class may be composed of any number of
members (such as constructors, properties, methods, and events) and data points (fields). In C#, classes
are declared using the class keyword, like so:
// A C# class type with 1 method.
class Calc
{
public int Add(int x, int y)
{
return x + y;
}
}
Chapter 5 will begin your formal examination of building class types with C#; however, Table 1-1
documents a number of characteristics pertaining to class types.
Table 1-1. CTS Class Characteristics
Class Characteristic
Meaning in Life
Is the class sealed or not?
Sealed classes cannot function as a base class to other
classes.
Does the class implement any interfaces? An interface is a collection of abstract members that provide
a contract between the object and object user. The CTS
allows a class to implement any number of interfaces.
Is the class abstract or concrete?
Abstract classes cannot be directly instantiated, but are
intended to define common behaviors for derived types.
Concrete classes can be instantiated directly.
15