title: Ambiguous call error with overloaded method that takes 2 delegates with different return types
body: <pre><code>class Program
  {
      public delegate void VoidMethodDelegate();
      public delegate int IntMethodDelegate();
  
      static void Main(string[] args)
      {
          Test(IntMethod);
          Test(VoidMethod);
      }
  
      static int IntMethod()
      {
          return 1;
      }
  
      static void VoidMethod()
      {
      }
  
      static void Test(VoidMethodDelegate method)
      {
      }
  
      static void Test(IntMethodDelegate method)
      {
      }
  }
  </code></pre>
  
  <p>I am trying to set up an overloaded method that will take two different types of delegates.  The delegates differ only by return type -- in both cases they take no input parameters.  So in the example above, I would like to be able to call Test() and pass it either a method that returns void, or a method that returns int.  When I compile the code above, I get these errors:</p>
  
  <blockquote>
    <p>error CS0121: The call is ambiguous
    between the following methods or
    properties:
    'ConsoleApplication1.Program.Test(ConsoleApplication1.Program.VoidMethodDelegate)'
    and
    'ConsoleApplication1.Program.Test(ConsoleApplication1.Program.IntMethodDelegate)'</p>
    
    <p>error CS0407: 'int
    ConsoleApplication1.Program.IntMethod()'
    has the wrong return type</p>
    
    <p>error CS0121: The call is ambiguous
    between the following methods or
    properties:
    'ConsoleApplication1.Program.Test(ConsoleApplication1.Program.VoidMethodDelegate)'
    and
    'ConsoleApplication1.Program.Test(ConsoleApplication1.Program.IntMethodDelegate)'</p>
  </blockquote>
  
  <p>I know I can work around the errors if I create the delegates with <em>new</em> instead of just passing the method directly, like this:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          Test(new IntMethodDelegate(IntMethod));
          Test(new VoidMethodDelegate(VoidMethod));
      }
  </code></pre>
  
  <p>But that syntax is messy, and I'd prefer to be able to pass the method directly, instead of having to wrap it in a call to <em>new</em>.  The only solution I've seen is to get rid of the overloaded version of Test() and instead use two different methods, each with a different name.</p>
  
  <p>Can anyone tell me why the compiler is complaining that this is ambiguous?  I don't understand whhy the compiler can't decide which of the two overloads to use.</p>