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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:20:59+00:00 2026-05-23T13:20:59+00:00

Is there something comparable to explicit interface implementation but for classes instead in C#?

  • 0

Is there something comparable to explicit interface implementation but for classes instead in C#?

Consider the following situation:

Company X provides a library containing a class as follows:

public class LibraryClass
{
    public virtual void A() { }

    public void DoWork()
    {
        // does something
    }
}

Company Y uses this library in one of its products and inherits from LibraryClass:

public class UserClass : LibraryClass
{
    public virtual void B() { }
}

So far everything works fine. But at someday X releases a new library version and adds a virtual method B()to LibraryClass:

public class LibraryClass
{
    public virtual void A() { }
    public virtual void B() { }

    public void DoWork()
    {
        // does something
        // now uses B with certain semantic assumptions
    }
}

Now Y updates to the new library version. While compiling with a reference to the new version, the compiler emits a warning saying that UserClass.B() is hiding the inherited method LibraryClass.B() and therefore should either specify the new keyword or override the method. Because there is a semantic gap between the existing method UserClass.B() and the newly introduced method LibraryClass.B() Y decides to introduce the new keyword because any existing override of UserClass.B() will probably not provide the semantics expected by DoWork() which would break the code. On the other hand Y wants to use a new feature of the library which would require an override of LibraryClass.B(). Now this is not possible: If the override would be done in a derived class of UserClass the override would refer to UserClass.B() due to the new keyword; an override of B in UserClass itself is not even allowed as it already defines a public method with that signature.

This situation could be solved if there was either a way in a derived class of UserClass to specify that the override refers to LibraryClass.B() which is not possible as far as I know -or- if B() could be explicitly overriden in UserClass:

public class UserClass : LibraryClass
{
    ...

    // Override this method in order to change the behavior of LibraryClass.B()
    public virtual void LibraryB() { }

    private void override LibraryClass.B()
    {
        LibraryB();
    }

    ...
}

Is there any way in the language to solve this situation other than renaming the original B() in UserClass (which might not even be possible if it was part of a library itself which is consumed by company Z)? If not, is this a C# limitation or a limitation of the CLR?

Sorry for the long post and thank you for reading up to this point.

Edit: This is not a CLR limitation. C++/CLI supports named overrides which solve the situation, so you could do something like virtual void LibraryB(void) = LibraryClass::B;. The C# design team probably just missed this issue.

  • 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-23T13:21:00+00:00Added an answer on May 23, 2026 at 1:21 pm

    Is there any way in the language to solve this situation other than…

    No, there isn’t. If you genuinely feel that this is a risk, perhaps use an interface-based design rather than inheritance. Personally, I feel it unlikely that this is going to cause you any significant issue, especially if you use more specific method names than B().

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

Sidebar

Related Questions

Is Berkley Packet Filter supported on Windows or is there something comparable which I
This question is related to a previous post . Is there something comparable to
Is there something like python's interactive REPL mode, but for Java? So that I
Here's an interface: public interface Foo<T> extends Comparable<Foo<T>> { ... } And there are
Is there something like the Python descriptor protocol implemented in other languages? It seems
Is there something special about Safari for Windows and AJAX? In other words: Are
Is there something like InstallShield that I can use for free?
Is there something like Python's getattr() in C#? I would like to create a
Is there something like a panel that I can use in a MFC application.
is there something like a Quickfix in Eclipse IDE available in VisualStudio 2008? Thanks,

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.