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 791893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:54:32+00:00 2026-05-14T21:54:32+00:00

I just hit a situation where a method dispatch was ambiguous and wondered if

  • 0

I just hit a situation where a method dispatch was ambiguous and wondered if anyone could explain on what basis the compiler (.NET 4.0.30319) chooses what overload to call

interface IfaceA
{

}

interface IfaceB<T>
{
    void Add(IfaceA a);
    T Add(T t);
}

class ConcreteA : IfaceA
{

}

class abstract BaseClassB<T> : IfaceB<T>
{
    public virtual T Add(T t) { ... }
    public virtual void Add(IfaceA a) { ... }
}

class ConcreteB : BaseClassB<IfaceA>
{
    // does not override one of the relevant methods
}

void code()  
{
    var concreteB = new ConcreteB();

    // it will call void Add(IfaceA a)
    concreteB.Add(new ConcreteA());
}

In any case, why does the compiler not warn me or even why does it compile?
Thank you very much for any answers.

  • 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-14T21:54:32+00:00Added an answer on May 14, 2026 at 9:54 pm

    It follows the rules in section 7.5.3.2 of the C# 4 specification (“Better function member”).

    First (well, after seeing that both methods are applicable) we need to check the conversions from argument types to parameter types. In this case it’s reasonably simple because there’s only one argument. Neither conversion of argument type to parameter type is “better” because both are converting from ConcreteA to IfaceA. It therefore moves on to the next set of criteria, including this:

    Otherwise, if MP has more specific
    parameter types than MQ, then MP is
    better than MQ. Let {R1, R2, …, RN}
    and {S1, S2, …, SN} represent the
    uninstantiated and unexpanded
    parameter types of MP and MQ. MP’s
    parameter types are more specific than
    MQ’s if, for each parameter, RX is not
    less specific than SX, and, for at
    least one parameter, RX is more
    specific than SX:specific than SX:

    • A type parameter is less specific than a non-type parameter.
    • …

    So even though the conversion is equally good, the overload using IfaceA directly (rather than via delegates) is deemed “better” because a parameter of type IfaceA is more specific than a parameter of type T.

    There’s no way of getting the compiler to warn on this behaviour – it’s just normal overload resolution.

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

Sidebar

Related Questions

just wondering if anyone knows of a truly restful Put/delete implementation asp.net mvc preview
I'm just starting out playing around with Linq Expressions and I've hit a wall.
I am just starting out with DI & unit testing and have hit a
Just what the title says, I need to change the password for an existing
Just looking for the first step basic solution here that keeps the honest people
just a quick question: I am a CS undergrad and have only had experience
Just bought a 2.4GHz Intel Core 2 Duo iMac with 2GB of memory and
Just getting my head around Ruby metaprogramming. The mixin/modules always manage to confuse me.
Just how much slower are events? I have written a streaming XML parser (that
Just installed the latest SDK for iPhone 2.1. When I go to File ->

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.