Esempio n. 1
0
        static void Main(string[] args)
        {
            Motorcycle moto = new Motorcycle("Yamaha", 200, 100);

            moto.RegisterWithMotorcyleEngine(OnMotorcycleEngineEvent);  //Method Group Conversion Syntax

            moto.RegisterWithMotorcyleEngine(new Motorcycle.MotorcycleHandler(OnMotorcycleEngineStop));
            //moto.RegisterWithMotorcyleEngine(new MotorcycleHandler(OnMotorcycleEngineStop)); if delegate global

            Motorcycle.MotorcycleHandler handler = OnMotorcycleEngineStop; //type Motorcycle.MotorcycleHandler
            //Motorcycle.MotorcycleHandler handler = new Motorcycle.MotorcycleHandler(OnMotorcycleEngineStop);
            moto.RegisterWithMotorcyleEngine(handler);
            //moto.UnRegisterWithMotorcyleEngine(handler);

            EventHandler handler2 = OnMotorcycleEngineStop;

            moto.RegisterWithMotorcyleEngine(hadnler2); //type EventHandler

            MotorcycleHandler handler3 = OnMotorcycleEngineStop;

            moto.RegisterWithMotorcyleEngine(handler3); //type MotorcycleHandler

            for (int i = 0; i < 6; i++)
            {
                moto.Accelerate(20);
            }
            Console.ReadLine();
        }
Esempio n. 2
0
 public void UnRegisterWithMotorcyleEngine(MotorcycleHandler methodToCall) //Remove registration function
 {
     motorcycleHandler -= methodToCall;
 }
Esempio n. 3
0
 public void RegisterWithMotorcyleEngine(MotorcycleHandler methodToCall) //Add registration function for the caller.
 {
     motorcycleHandler += methodToCall;
     //Delegate.Combine(motorcycleHandler, methodToCall);
 }