Created
January 7, 2018 23:09
-
-
Save luisdeol/244954b71abdcfb3060d0c079b694f92 to your computer and use it in GitHub Desktop.
Event using event keyword and Event Handler
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 | |
| { | |
| public class MyArgs : EventArgs | |
| { | |
| public MyArgs(string value) | |
| { | |
| Value = value; | |
| } | |
| public string Value { get; set; } | |
| } | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var pub = new Publisher(); | |
| pub.OnChange += (sender, e) => Console.WriteLine($"Event raised: {e.Value}"); | |
| pub.OnChange += (sender, e) => Console.WriteLine($"Event raised: {e.Value}"); | |
| pub.Raise(); | |
| Console.ReadKey(); | |
| } | |
| } | |
| public class Publisher | |
| { | |
| public event EventHandler<MyArgs> OnChange = delegate { }; | |
| public void Raise() | |
| { | |
| OnChange(this, new MyArgs("FIIIRED!")); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment