notes here
Last active
July 13, 2017 06:45
-
-
Save solkar/0ab5c135039c572df646664f764678b4 to your computer and use it in GitHub Desktop.
Subscribing for events using lambda expressions
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
public class EventClassWithoutEvent | |
{ | |
public Action OnChange { get; set; } | |
public void Raise() | |
{ | |
if (OnChange != null) | |
{ | |
OnChange(); | |
} | |
} | |
} |
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
public partial class Program | |
{ | |
private static void CreateAndRaiseEvent() | |
{ | |
EventClassWithoutEvent ev = new EventClassWithoutEvent(); | |
ev.OnChange += () => | |
Console.WriteLine("1st: Event raised"); | |
ev.OnChange += () => | |
Console.WriteLine("2nd: Event raised"); | |
ev.Raise(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment