title: c# Array of delegate references
body: <p>When referencing other classes we use delegates. During unit testing we override these values.</p>
  
  <p>I have a class which references over 20 other classes, so I thought I'd create an array of delegates. If I create a static array of these delegates (see code below) it stores the values of the delegates, not the reference to the delegate.</p>
  
  <p>As a result the unit tests can't update the values. To work around this I've created the array of delegates when I want to use them but I'd like the code below to work.</p>
  
  <pre><code>private static Func&lt;int, bool&gt; firstMethod = ExternalClass1.Method;
  private static Func&lt;int, bool&gt; secondMethod = ExternalClass2.Method;
  private static Func&lt;int, bool&gt; thirdMethod = ExternalClass3.Method;
  
  private static Func&lt;int, bool&gt;[] handlers = { first, second, third };
  
  public bool Test(int value)
  {
      foreach (var handler in handlers)
      {
          if (handler.Invoke(value) == true)
          {
               return true;
          }
      }
  
      return false;
  }
  </code></pre>