Sorry to ask all, but I’m an old hand Vb.net guy who’s transferring to c#. I have the following piece of code that seems to activate when the (in this case) postAsync method is fired. I just don;t understand what the code is doing (as follows):-
app.PostCompleted +=
(o, args) =>
{
if (args.Error == null)
{
MessageBox.Show("Picture posted to wall successfully.");
}
else
{
MessageBox.Show(args.Error.Message);
}
};
if anyone could explain what the += (o,args) => is actually acheiving I’d be so greatful….
many thanks in advance.
Tim
(o,args) =>defines a lambda expression that takes two parameters namedoandargs. The types of those parameters is inferred according to the type ofPostCompleted(ifPostCompletedis anEventHandler, then they will be respectively of typeObjectandEventArgs). The expression’s body then follows after the=>.The result is than added as an handler to
PostCompleted.As such, it’s a less verbose way to write:
Which is a shorthand for: