Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this code mean (s, e)?

How does this code work?

      app.InstallStateChanged += (s, e) => UpdateUI();
      NetworkChange.NetworkAddressChanged +=
            (s, e) => UpdateNetworkIndicator();

Can someone please unscramble this?

The code comes from an example used in a silverlight 4 OOB systems http://msdn.microsoft.com/en-us/library/dd833066(v=VS.95).aspx

UpdateNetworkIndicator does not return anything. UpdateUI does not return anything.

like image 519
Hunt Avatar asked Sep 01 '11 13:09

Hunt


1 Answers

This is a lambda expression that contains multiple parameters. In this case (as you are using the function to replace an event handler) they are equivalent to the object and EventArgs parameters.

Your code is equivalent to the below

app.InstallStateChanged += OnInstallStateChanged;
NetworkChange.NetworkAddressChanged += OnNetworkAddressChanged;

/* ... */

private void OnInstallStateChanged(object s, EventArgs e)
{
    UpdateUI();
}

private void OnNetworkAddressChanged(object s, EventArgs e)
{
    UpdateNetworkIndicator();
}
like image 69
Steve Greatrex Avatar answered Sep 22 '22 06:09

Steve Greatrex