public CH0603() { MyClass2 mc = new MyClass2(); mc.PrintOut("Object"); IIfc1 ifc1 = (IIfc1)mc; ifc1.PrintOut("Interface"); }
static void Main() { MyClass mc = new MyClass(); IIfc1 ifc1 = (IIfc1)mc; // Get ref to IIfc1 IIfc2 ifc2 = (IIfc2)mc; // Get ref to IIfc2 mc.PrintOut("object."); // Call through class object ifc1.PrintOut("interface 1."); // Call through IIfc1 ifc2.PrintOut("interface 2."); // Call through IIfc2 }
static void Main() { MyClass mc = new MyClass(); // Create class object. mc.PrintOut("object"); // Call class object implementation method. IIfc1 ifc = (IIfc1)mc; // Cast class object ref to interface ref. ifc.PrintOut("interface"); // Call interface method. }
static void Main() { MyClass mc = new MyClass(); mc.PrintOut("object."); // IIfc1 ifc = (IIfc1)mc; IIfc1 ifc = mc as IIfc1; ifc.PrintOut("interface."); }
static void Main() { Myclass mc = new Myclass(); mc.PrintOut("object"); IIfc1 ifc = mc as IIfc1; ifc.PrintOut("interface"); }
public void demo7() { ClassIn ci = new ClassIn(); IIfc1 ifc1 = (IIfc1)ci; ifc1.PrintOut("interface 1"); IIfc2 ifc2 = (IIfc2)ci; ifc2.PrintOut("interface 2"); }
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. }
static void Main() { MyClass mc = new MyClass(); IIfc1 ifc1 = mc as IIfc1; ifc1.PrintOut("interface 1"); IIfc2 ifc2 = mc as IIfc2; ifc2.PrintOut("interface 2"); }
static void Main(string[] args) { MyClass myClass = new MyClass(); //创建对象 myClass.Method("myClass"); //访问显式接口成员 IIfc1 ifc1 = myClass as IIfc1; //获取iifc1的引用 IIfc2 ifc2 = myClass as IIfc2; //获取iifc2的引用 ifc1.PrintOut("interface1"); ifc2.PrintOut("interface2");//调用显式实现方法 Console.ReadKey(); }
static void Main(string[] args) { MyClass mc = new MyClass(); IIfc1 ifc1 = (IIfc1)mc; IIfc2 ifc2 = (IIfc2)mc; mc.PrintOut("object"); ifc1.PrintOut("interface 1"); ifc2.PrintOut("interface 2"); }
static void Main(string[] args) { Derived d = new Derived(); d.PrintOut("object."); IIfc1 ifc1 = d as IIfc1; if (ifc1 != null) { ifc1.PrintOut("IIfc1"); } }
static void Main(string[] args) { MyClass mc = new MyClass(); mc.PrintOut("object"); IIfc1 ifc1 = mc as IIfc1; if (ifc1 != null) { ifc1.PrintOut("interface"); } IIfc2 ifc2 = mc as IIfc2; if (ifc2 != null) { ifc2.PrintOut("interface"); } }