Sunday, November 7, 2010

Currying in C#

During reviewing samples for Async Ctp I have found such code:

var cts = new CancellationTokenSource();
btnCancel.Click += cts.EventHandler;  // !!!!
 
public static class Extensions
{
    public static void EventHandler(this CancellationTokenSource cts, 
        object sender, EventArgs e)
    {
        cts.Cancel();
    }
}

Did you know it was possible ?

1 comment: