[Ironruby-core] Delegates (agian)

Curt Hagenlocher curt at hagenlocher.org
Thu Oct 25 18:22:54 EDT 2007

On 10/25/07, Dermot Hogan <lists at ruby-forum.com> wrote:
> In .NET C# etc, the += and -= for delegates don't really mean the same
> as they do in other contexts. They means 'add/remove' a delegate
> into/from the delegate queue. You can't say
> x = new EventHandler(mymethod)
> all you can do is add/remove. It's another example of syntactic kluging
> IMO. It does work well in practise, though.

This is actually a fundamental property of events on a CLR / IL level.
Events are exposed as a pair of functions to add a handler and remove a
handler.  The reason for this is efficiency; if every Control in a Windows
Forms application defined a slot for each of its events, you'd have an
immense number of slots defined -- even though most of them would
effectively have a value of null.

Curt Hagenlocher
curt at hagenlocher.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20071025/97fa8bb7/attachment.html 

More information about the Ironruby-core mailing list