Created
January 7, 2018 22:58
-
-
Save luisdeol/38790cb6c31253d1d338e7c498adeee2 to your computer and use it in GitHub Desktop.
Raising an event using Action delegate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| namespace create_implement_events_callbacks | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var publisher = new Publisher(); | |
| publisher.OnChange += () => Console.WriteLine("Merry Christmas!"); | |
| publisher.OnChange += () => Console.WriteLine("Happy New Year"); | |
| publisher.Raise(); | |
| Console.ReadKey(); | |
| } | |
| } | |
| public class Publisher | |
| { | |
| public Action OnChange { get; set; } | |
| public void Raise() | |
| { | |
| OnChange?.Invoke(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment