title: Use of unassigned local variable when creating an anonymous function closing on itself
body: <p>Why does this declaration+assignment cause an error:</p>
  
  <pre><code>// Use of unassigned local variable 'handler'.
  SessionEndingEventHandler handler = (sender, e) =&gt; { isShuttingDown = true; SystemEvents.SessionEnding -= handler; };
  </code></pre>
  
  <p>while this does not:</p>
  
  <pre><code>SessionEndingEventHandler handler = null;
  handler = (sender, e) =&gt; { isShuttingDown = true; SystemEvents.SessionEnding -= handler; };
  </code></pre>
  
  <p>In is intuitive that the first statement should cause an error but not immediately clear why the second one is not.</p>
  
  <p>Furthermore, how could I tell if the <code>SystemEvents.SessionEnding</code> event has been actually unsubscribed after the call to <code>handler(null, null)</code>? The <code>GetInvocationList</code> only works with delegates.</p>
  
  <pre><code>SystemEvents.SessionEnding += handler;
  handler(null, null);
  </code></pre>