//method which gets the event args protected virtual void RaiseSwitchFlipped(SwitchFlippedEventArgs args) { // We must check that the event is not null. It is null // if no one registered to the event. // if (SwitchFlipped != null) { SwitchFlipped(this, args); } }
public void Flip() { if (_state == SwitchState.Off) { _state = SwitchState.On; } else { _state = SwitchState.Off; } // We call the protected method that raises the event. SwitchFlippedEventArgs eventArgs = new SwitchFlippedEventArgs(_state); RaiseSwitchFlipped(eventArgs); }
public static void OnSwitchFlipped(object sender, SwitchFlippedEventArgs args) { Console.WriteLine("This is the Light, switch flipped to state: " + args.State); }
static void OnSwitchFlipped(object sender, SwitchFlippedEventArgs args) { Console.WriteLine("Switch flipped to state: " + args.State); }