This chapter looked at compilation units, namespaces, and assemblies and discussed different fundamental ways to configure these important C# and .NET elements.

The following are the important points mentioned in this chapter.

Namespaces are used for two main purposes:

  • To organize our classes and other types into logical hierarchies when we write our own programs

  • As a convenient way to access classes and other types in other components

When a class is inserted into a namespace, its name becomes a combination of the namespace name and the class's short name. This fact prevents name clashes.

A namespace is a logical entity that transcends physical source files and assemblies. A namespace can span over several compilation units and several assemblies.

Zero or more namespaces can be positioned beside each other in a compilation unit or in another namespace. Consequently, namespaces can be nested inside each other to any required depth.

Classes and other types defined outside any explicitly defined namespace automatically belong to a global nameless namespace.

The using directive can be used in two ways. First, it allows us to write shorter convenient names in our source code when we reference classes with otherwise long qualified names. Second, it allows us to create aliases for namespaces and classes (or other types).

It is possible to compile many compilation units into the same assembly.

By using the /t[arget]: compiler command, you can choose whether an assembly will be a DLL (by writing library after the command) for reuse only or a standalone executable (by writing .exe after the command).

The namespaces and the classes (types) contained in an assembly can be made available to another EXE or DLL created by the compiler by using the /r[eference]: command.

It is often more convenient to have several smaller DLL assemblies than one large DLL (or EXE).

The Ildasm.exe utility that ships with the .NET SDK is a simple tool for inspecting the contents of a DLL or EXE assembly.


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: