Information Technology Reference
In-Depth Information
Referencing Other Assemblies
In Chapter 1, you took a high-level look at the compilation process. You saw that the compiler
takes the source code file and produces an output file called an assembly . In this chapter, you
will take a closer look at assemblies and how they are produced and deployed. You will also
look at how namespaces help organize types.
All the programs you've seen so far have, for the most part, declared and used their own
classes. In many projects, however, you will want to use classes or types from other assemblies.
These other assemblies might come from the BCL, a third-party vendor, or you might have cre-
ated them yourself. These are called class libraries , and the names of their assembly files
generally end with the .dll extension rather than the .exe extension.
For example, suppose that you want to create a class library that contains classes and
types that can be used by other assemblies. The source code for a simple library is shown in the
following example and is contained in a file called SuperLib.cs . The library contains a single
public class called SquareWidget . Figure 10-1 illustrates the production of the DLL.
public class SquareWidget
{
public double SideLength = 0;
public double Area
{
get { return SideLength * SideLength; }
}
}
Figure 10-1. The SuperLib source code and the resulting assembly
Search WWH ::




Custom Search