Created
March 29, 2012 22:23
-
-
Save dtryon/2244355 to your computer and use it in GitHub Desktop.
Simple action event
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; | |
| public class OnLoadTest | |
| { | |
| static void Main() | |
| { | |
| Page page = new Page(); | |
| //Wire up the event delegate | |
| page.Load += new Action<object, EventArgs>(MyHandler); | |
| //Fire the event | |
| page.Initialize(); | |
| Console.WriteLine("Press <enter> to quit"); | |
| Console.ReadLine(); | |
| } | |
| static void MyHandler(object sender, EventArgs e) | |
| { | |
| Console.WriteLine("In MyHandler"); | |
| } | |
| } | |
| public class Page | |
| { | |
| public void Initialize() | |
| { | |
| //Do a few things | |
| OnLoad(); | |
| } | |
| public event Action<object, EventArgs> Load; | |
| protected void OnLoad() | |
| { | |
| if (Load != null) | |
| { | |
| EventArgs args = new EventArgs(); | |
| Load(this, args); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment