Information Technology Reference
In-Depth Information
Explicit Interface Member Implementations
You saw in a previous section that you can use a single class implementation to implement
multiple interfaces. This was illustrated in Figures 17-5 and 17-6.
But what if you want separate implementations for each interface? In this case, you can
create what are called explicit interface member implementations . An explicit interface mem-
ber implementation has the following characteristics:
￿
Like all interface implementations, it is placed in the class or struct implementing the
interface.
￿
It is declared using a qualified interface name , which consists of the interface name and
member name, separated by a dot.
For example, the following code shows the syntax for declaring explicit interface member
implementations. Each of the two interfaces implemented by MyClass implements its own ver-
sion of method PrintOut .
class MyClass : IIfc1, IIfc2
{ Qualified interface name
void IIfc1.PrintOut (string s) // Explicit implementation
{ ... }
void IIfc2.PrintOut (string s) // Explicit implementation
{ ... }
}
Figure 17-8 illustrates the class and interfaces. Notice that the boxes representing the
explicit interface member implementations are not shown in gray, since they now represent
actual code.
Figure 17-8. Explicit interface member implementations
Search WWH ::




Custom Search