Using system;
Namespace classlibrary2
{
Interface iemploy // Interface
{
Void speak (); // Method
}
Class Hello: iemploy // implementation interface of the Hello class
{
Public void speak () // Implementation Method
{
Console. writeline ("Hello: Friend ");
}
}
Class sorry: iemploy // sorry class implementation Interface
{
Public void speak () // Implementation Method
{
Console. writeline ("Sorry: Friend ");
}
}
}
Implementation
// Directly call
Iemploy Ie = new Hello ();
Ie. Speak (); // call the interface implemented by the Hello class
Iemploy Ie = new sorry ();
Ie. Speak ();
// Reflection call remember that the reflected space references using system. reflection;
Assembly ASM = assembly. Load ("classlibrary2"); // reflection Space
Type type = ASM. GetType ("classlibrary2.hello"); // reflection of classes in the space
Object assclas = activator. createinstance (type); // the specified class in the specified Space Reflected by dynamic strength.
Iemploy Ie = (iemploy) assclas; // convert to interface type
// Common methods