this.Loaded += (s, e) => this.loaded = true;?

c#-3.0, events, lambda

Solution

This may make it slightly clearer, just by renaming:

this.Loaded += (sender, args) => this.loaded = true;

Or by giving them types:

this.Loaded += (object sender, EventArgs args) => this.loaded = true;

They're the parameters for the delegate. Here's the equivalent in C# 2:

this.Loaded += delegate (object sender, EventArgs args) { this.loaded = true; };

Does that help?

Here's the equivalent in C# 1 (fortunately there are no captured variables, which makes life a bit easier...)

this.Loaded += new EventHandler(SetLoadedToTrue);

...

private void SetLoadedToTrue(object sender, EventArgs args)
{
    this.loaded = true;
}

(That's all assuming the `Loaded` event is of type EventHandler; if it's not, the signature would be different in the obvious way.)

Problem

would someone please write this code: this.Loaded += (s, e) => this.loaded = true; into several code lines so I can retrace the meaning? In my code sample there is no s or e ?

Original source