Reference one object by multiple interfaces : Object Reference : Class C# Examples


C# Examples » Class » Object Reference »

 

Reference one object by multiple interfaces









    
using  System;

interface  Interface1  {
            void  PrintOut(string  s);
}

interface  Interface2  {
            void  PrintOut(string  s);
}

class  MyClass  :  Interface1,  Interface2
{
      public  void  PrintOut(string  s)
      {
            Console.WriteLine(s);
      }
}

class  MainClass
{
      static  void  Main()
      {
            MyClass  mc  =  new  MyClass();
            Interface1  ifc1  =  (Interface1)mc;
            Interface2  ifc2  =  (Interface2)mc;

            mc.PrintOut("object.");
            ifc1.PrintOut("interface  1.");
            ifc2.PrintOut("interface  2.");
      }
}
    
   
  
   



Output

object.
interface 1.
interface 2.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Object Reference