Reputation: 2815
I was wondering if anyone could tell me the raw code equivalent to the += operator for adding a method to an event. I am curious to how it it works from a technical standpoint.
Upvotes: 5
Views: 174
Reputation: 1064064
An event
defines a set of methods including "add" and "remove" (in the same way that a property defines "get" and "set"). to this is effectively:
obj.add_SomeEvent(handler);
Internally, the event could do anything; there are 2 common cases:
EventHandlerList
implementationsWith a delegate, it effectively uses Delegate.Combine
:
handler = Delegate.Combine(handler, value);
With an EventHandlerList
there is a key object:
Events.AddHandler(EventKey, value);
Upvotes: 10