Information Technology Reference
In-Depth Information
The second assembly contains the declaration of a class called
DerivedClass
that inherits from
MyBaseClass
, declared in the first assembly. The source file is named
Program.cs
. Figure 7-14 illus-
trates the two assemblies.
DerivedClass
has an empty body but inherits method
PrintMe
from
MyBaseClass
.
Main
creates an object of type
DerivedClass
and calls its inherited method
PrintMe
.
// Source file name Program.cs
using System;
using BaseClassNS;
↑
Namespace containing declaration of base class
namespace UsesBaseClass
{
Base class in other assembly
↓
class DerivedClass: MyBaseClass {
// Empty body
}
class Program {
static void Main( )
{
DerivedClass mdc = new DerivedClass();
mdc.PrintMe();
}
}
}
This code produces the following output:
I am MyBaseClass
Figure 7-14.
Inheriting across assemblies