title: Passing parent object reference in Lambdas
body: <p>I'm trying to understand how the following lambda executes.</p>
  
  <pre><code>MyObject.LoginCompleted += (result) =&gt; DoSomething(result, MyObject);
  </code></pre>
  
  <p>I'm curious about the use of <code>MyObject</code> as a function parameter. Is this technically correct and will actually pass the reference of <code>MyObject</code> to <code>DoSomething()</code> when the event occurs? If so, how does a lambda expression store this reference inside itself when the above statement is executed? I'm curious because I can't think of an equivalent non-lambda statement for this. Say:</p>
  
  <pre><code>MyObject.LoginCompleted += DoSomething;
  </code></pre>
  
  <p>Now unless <code>LoginCompleted</code> event itself has a parameter for the parent object (e.g. <code>LoginCompleted(object sender...)</code> kind of stuff), we'll normally not be able to find about MyObject inside <code>DoSomething()</code>. This doesn't happen in the case of lambda, where we can send <code>MyObject</code> as a parameter to <code>DoSomething()</code> even when the event itself doesn't carry that information.</p>
  
  <p>So my quesitons are:</p>
  
  <ol>
  <li>Is my assumption about normal event handlers (through method-delegate) correct, or is there an equivalent code available which I'm missing?</li>
  <li>Explanation of how lambda is storing the object reference internally?</li>
  </ol>