title: Pass a method as a parameter in C# from a different class
body: <p>I have a class "A" from which I want to call a method in another different class "B" by passing a function as a parameter. Function passed as a parameter is in class B. So how to do it if I am calling method from class A? </p>
  
  <p>I am using Visual Studio 2008 and .NET Framework 3.5.</p>
  
  <p>I have seen this <a href="https://stackoverflow.com/questions/2082615/pass-method-as-parameter-using-c-sharp">post</a> but it tells how to call a main method by passing another method as a parameter but from the same class, not different class.</p>
  
  <p>For example, in that post below example is provided:</p>
  
  <pre><code>public class Class1
  {
      public int Method1(string input)
      {
          //... do something
          return 0;
      }
  
      public int Method2(string input)
      {
          //... do something different
          return 1;
      }
  
      public bool RunTheMethod(Func&lt;string, int&gt; myMethodName)
      {
          //... do stuff
          int i = myMethodName("My String");
          //... do more stuff
          return true;
      }
  
      public bool Test()
      {
          return RunTheMethod(Method1);
      }
  }
  </code></pre>
  
  <p>but how to do the following:</p>
  
  <pre><code>public Class A
  {
          (...)
  
          public bool Test()
          {
              return RunTheMethod(Method1);
          }
  
          (...)
  }
  
  
  public class B
  {
      public int Method1(string input)
      {
          //... do something
          return 0;
      }
  
      public int Method2(string input)
      {
          //... do something different
          return 1;
      }
  
      public bool RunTheMethod(Func&lt;string, int&gt; myMethodName)
      {
          //... do stuff
          int i = myMethodName("My String");
          //... do more stuff
          return true;
      }
  }
  </code></pre>