title: C# - anonymous functions and event handlers
body: <p>I have the following code:  </p>
  
  <pre><code>public List&lt;IWFResourceInstance&gt; FindStepsByType(IWFResource res)  
  {  
      List&lt;IWFResourceInstance&gt; retval = new List&lt;IWFResourceInstance&gt;();  
      this.FoundStep += delegate(object sender, WalkerStepEventArgs e)   
                        {   
                          if (e.Step.ResourceType == res) retval.Add(e.Step);   
                        };  
      this.Start();  
      return retval;
  }  
  </code></pre>
  
  <p>Notice how I register my event member (FoundStep) to local in-place anonymous function.</p>
  
  <p>My question is: when the function 'FindStepByType' will end - will the anonymous function be removed automatically from the delegate list of the event or I have to manually remove it before steping out the function? (and how do I do that?)</p>
  
  <p>I hope my question was clear. </p>