title: Local variables with Delegates
body: <p>This <strike>is clearly not</strike> appears like it wouldn't be a best practice. Can someone explain why it would not be a best practice or how this works? Any books or articles  providing an explanation would be appreciated.</p>
  
  <pre><code>//The constructor
  public Page_Index() {
  
      //create a local value
      string currentValue = "This is the FIRST value";
  
      //use the local variable in a delegate that fires later
      this.Load += delegate(object sender, EventArgs e) {
          Response.Write(currentValue);
      };
  
      //change it again
      currentValue = "This is the MODIFIED value";
  
  }
  </code></pre>
  
  <p>The value that is output is the second value <em>"Modified"</em>. What part of the compiler magic is making this work? Is this as simple as keeping track of the value on the heap and retrieving it again later?</p>
  
  <p>[Edit]: Given some of the comments, changing the original sentence some...</p>