Implement three interfaces - CSharp Custom Type

CSharp examples for Custom Type:interface

Description

Implement three interfaces

Demo Code

using System;//w w w.j  a v a  2 s  .  c  o m
interface IAlarm {
   bool On { get; set; }
   void Snooze( );
}
interface IClock {
   void SetTime( );
}
interface IRadio {
   void SetStation( double station_id );
}
public class AlarmClock : IAlarm, IClock, IRadio {
   private bool   m_bOnOff;
   public bool On
   {
      get
      {
         return m_bOnOff;
      }
      set
      {
         m_bOnOff = value;
      }
   }
   public    void Snooze( )
   {
      Console.WriteLine("IAlarm.Snooze");
   }
   public    void SetTime( )
   {
      Console.WriteLine("IClock.SetTime");
   }
   public    void SetStation( double station_id )
   {
      Console.WriteLine("IRadio.SetStation( {0} )", station_id );
   }
}
public class MainClass {
   public static void Main( ) {
      AlarmClock a = new AlarmClock( );
      IAlarm ialarm = (IAlarm)a;
      ialarm.On = false;
      ialarm.Snooze( );
      IClock iclock = (IClock)a;
      iclock.SetTime( );
      IRadio iradio = (IRadio)a;
      iradio.SetStation( 98.1 );
   }
}

Result


Related Tutorials