Delegate, Lambda and more … C# versions comparative

C# event handler delegate changed according to C# versions.

Here is a sample, based on UnhandledException event

in the beginning was

d.UnhandledException += new UnhandledExceptionEventHandler(d_UnhandledException);
//...

void d_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
  Console.WriteLine("Ouch!");
}

currently, lambda version is quicker to write and easier to understand

d.UnhandledException += (sender, e) => { Console.WriteLine("Ouch!"); };

ain’t it ? ๐Ÿ˜‰

Maybe Visual Studio Intellisense helps you with old style form, and you have to write the full version manually (do you snippet ?).

In Initializing things in C# post I found a quick reference to event handler, anonymous type, lambda, object initialization, etc
with clearfull samples according to C# versions 1, 2 and 3.

Have a nice reading ๐Ÿ˜‰

Technorati tags: CSharp, Lambda, Delegate
Advertisements

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: