Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 979315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:12:02+00:00 2026-05-16T04:12:02+00:00

class Program { public delegate void VoidMethodDelegate(); public delegate int IntMethodDelegate(); static void Main(string[]

  • 0
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)
    {
    }
}

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:

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)’

error CS0407: ‘int
ConsoleApplication1.Program.IntMethod()’
has the wrong return type

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)’

I know I can work around the errors if I create the delegates with new instead of just passing the method directly, like this:

    static void Main(string[] args)
    {
        Test(new IntMethodDelegate(IntMethod));
        Test(new VoidMethodDelegate(VoidMethod));
    }

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 new. 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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:12:03+00:00Added an answer on May 16, 2026 at 4:12 am

    Basically this is a corollary of how overloading is performed, and how method group conversions are resolved. I can try to wade through the spec to find the exact reasons if you like, but the bad news is that’s just the way it is. It’s possible there’s a compiler bug in this case, but it’s more likely that it’s just a tricky bit of the spec.

    I think that this SO question may be relevant, but I haven’t checked yet.

    Rather than resolve it using new, I would suggest take the option of using different method names. Overloading has all kinds of sneaky corner cases – this one is at least relatively harmless in that it’s causing a compile-time error rather than picking the overload you don’t want at execution time. Removing overloading is often a good thing 🙂

    EDIT: I’m pretty sure that other SO question is relevant, actually. I suggest you get yourself a cup of coffee, the C# 4 spec, and then read Eric’s answer very carefully. Then change the method names so you don’t have to think about it any more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 488k
  • Answers 488k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For the report manager (2005) IF your machine is on… May 16, 2026 at 8:45 am
  • Editorial Team
    Editorial Team added an answer You have pthread on windows http://sourceware.org/pthreads-win32/ which is quite stable… May 16, 2026 at 8:45 am
  • Editorial Team
    Editorial Team added an answer The Json method returns a JsonResult. Not a JSON string.… May 16, 2026 at 8:45 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

public class Program { delegate void Srini(string param); static void Main(string[] args) { Srini
class SimpleDelegate { public delegate void LogHandler(string message); public void Process(LogHandler logHandler) { if
Why can't I use the event declared in Base from Sub ? class Program
In the following console application example, the event is defined like this: public delegate
I want to capture output of a Perl program and display output data (string
How do I define a DynamicMethod for a delegate that has an out -parameter,
Like Anonymous Methods ,the delegates i am declaring down using delegate keyword are anonymous
I got stuck up while dynamically assigning methods to a delegate instance through reflection.
I have been looking at Reflection.Emit recently. I wrote a simple program that generates
I'm trying to develop a class that supports an asynchronus method invocation. This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.