Information Technology Reference
In-Depth Information
For example, in the following code, class MyClass declares explicit interface member
implementations for the members of the two interfaces. Notice that in this example there are
only explicit interface member implementations. There is no class-level implementation.
interface IIfc1 { void PrintOut(string s); } // Declare interface
interface IIfc2 { void PrintOut(string t); } // Declare interface
class MyClass : IIfc1, IIfc2
{ Qualified interface name
void IIfc1.PrintOut(string s) // Explicit interface member
{ // Implementation
Console.WriteLine("IIfc1: {0}", s);
}
Qualified interface name
void IIfc2.PrintOut(string s) // Explicit interface member
{ // Implementation
Console.WriteLine("IIfc2: {0}", s);
}
}
class Program
{
static void Main()
{
MyClass mc = new MyClass(); // Create class object
IIfc1 ifc1 = (IIfc1) mc; // Get reference to IIfc1
ifc1.PrintOut("interface 1."); // Call explicit implementation
IIfc2 ifc2 = (IIfc2) mc; // Get reference to IIfc2
ifc2.PrintOut("interface 2."); // Call explicit implementation
}
}
This code produces the following output:
IIfc1: interface 1.
IIfc2: interface 2.
Search WWH ::




Custom Search