Created
January 3, 2010 01:57
-
-
Save chaliy/267776 to your computer and use it in GitHub Desktop.
This file contains 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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
TestEvents test = new TestEvents(); | |
test.SomethingOccured += (s, e) => Console.WriteLine("Test1"); | |
test.SomethingOccured += (s, e) => Console.WriteLine("Test2"); | |
test.SomethingOccured -= (s, e) => Console.WriteLine("Test1"); | |
test.SomethingOccured -= (s, e) => Console.WriteLine("Test2"); | |
test.FireSomethingOccured(); | |
} | |
public class TestEvents | |
{ | |
private readonly EventHandlerList _events = new EventHandlerList(); | |
private readonly static object SomethingOccuredEvent = new object(); | |
public event EventHandler<EventArgs> SomethingOccured | |
{ | |
add | |
{ | |
_events.AddHandler(SomethingOccuredEvent, value); | |
} | |
remove | |
{ | |
_events.RemoveHandler(SomethingOccuredEvent, value); | |
} | |
} | |
public void FireSomethingOccured() | |
{ | |
var somethingOccured = _events[SomethingOccuredEvent] as EventHandler<EventArgs>; | |
if (somethingOccured != null) | |
{ | |
somethingOccured(this, EventArgs.Empty); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment