Information Technology Reference
In-Depth Information
When the MyCorp company ships you the new updated assembly, you can use it by mod-
ifying the
MyWidgets
program as shown here. Notice that instead of just using the class name
(since it's ambiguous between the two class libraries), you preface the namespace name to the
class name and separate the two with a period. The entire string, with the namespace name
and the class name, is called the
fully qualified name
.
class WidgetsProgram {
static void Main( )
{
Fully qualified name
Fully qualified name
↓
↓
MyCorp.SuperLib.
SquareWidget sq = new MyCorp.SuperLib.SquareWidget();
↑
↑
Namespace name
Class name
CircleWidget circle = new CircleWidget();
...
Now that you have explicitly specified the
SuperLib
version of
SquareWidget
in your code,
the compiler will no longer have a problem distinguishing the classes. The fully qualified name
is a bit long to type, but at least you can now use both libraries. A little later in the chapter, you'll
use the
using
alias directive to solve the inconvenience of having to repeatedly type in the fully
qualified name.
If the
UltraLib
assembly is also updated with a namespace by the company that produces
it, the ABCCorp company, the compile process would be as shown in Figure 10-5.
Figure 10-5.
Class libraries with namespaces