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

  • Home
  • SEARCH
  • 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 8436367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:09:39+00:00 2026-06-10T07:09:39+00:00

I have base class A public class A { public virtual void Method(A parameter)

  • 0

I have base class A

public class A
{
    public virtual void Method(A parameter)
    {
        Console.WriteLine(MethodBase.GetCurrentMethod());
    }
    public virtual void Method(B parameter)
    {
        Console.WriteLine(MethodBase.GetCurrentMethod());
    }
}

Inhereted B

public class B : A
{
    public virtual void Method(object parameter)
    {
        Console.WriteLine(MethodBase.GetCurrentMethod());
    }

    public override void Method(A parameter)
    {
        Console.WriteLine(MethodBase.GetCurrentMethod());
    }

    public override void Method(B parameter)
    {
        Console.WriteLine(MethodBase.GetCurrentMethod());
    }
}

Static class S with extension method

public static class S
{
    public static void Method(this B instance, B parameter)
    {
        Console.WriteLine(MethodBase.GetCurrentMethod());
    }
}

Example we create instance of type B and invoke Method on it, we expect that it will be public override void Method(B parameter) actual result is public virtual void Method(object parameter).

var b = new B();
b.Method(new B()); // B.Method (Object parameter) Why???

Why compiler doesn’t select more suitible method???
UPD And why it is not extension method?

  • 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-06-10T07:09:40+00:00Added an answer on June 10, 2026 at 7:09 am

    Why compiler doesn’t select more suitible method?

    Because it’s following the rules of the language specification, where any candidate methods originally declared in a base class (over if they’re overridden in a derived class) are ignored when finding a candidate method, unless the derived class doesn’t have any applicable methods, at which point the search moves up to the base class, etc.

    This is designed to avoid the "brittle base class" problem, but I find that hard to swallow in the face of the method being overridden in the derived class.

    The relevant bit of the C# 4 specification is 7.4, which ends with this:

    For member lookups in types other than type parameters and interfaces, and member lookups in interfaces that are strictly single-inheritance (each interface in the inheritance chain has exactly zero or one direct base interface), the effect of the lookup rules is simply that derived members hide base members with the same name or signature.

    EDIT: About extension methods…

    And why it is not extension method?

    From section 7.6.5.2 of the spec:

    In a method invocation (§7.5.5.1) of one of the forms

    expr . identifier ( )
    expr . identifier ( args )
    expr . identifier < typeargs > ( )
    expr . identifier < typeargs > ( args )
    

    if the normal processing of the invocation finds no applicable methods, an attempt is made to process the construct as an extension method invocation

    So an extension method is only used as a last resort, basically.

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

Sidebar

Related Questions

I have seen this question http://www.careercup.com/question?id=384062 class Base { public : virtual void method
I have a question, here are two classes below: class Base{ public: virtual void
I have created an abstract base class Animal which has public virtual abstract method
Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)
I have base class and Execute virtual method. I override execute method in derived
I have a base class: class motorcycle { public: virtual int speed() { return
I have the following scenario :- template <typename T> class Base { public: virtual
I have two classes: public class MyBase { public virtual void DoMe() { }
I have a follwing class structure: public abstract class AbstractFoo { public virtual void
in this link , they have this code: public class Base { public virtual

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.