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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:57:41+00:00 2026-05-11T12:57:41+00:00

I’m learning C# coming from C++ and have run into a wall. I have

  • 0

I’m learning C# coming from C++ and have run into a wall.

I have an abstract class AbstractWidget, an interface IDoesCoolThings, and a class which derives from AbstractWidget called RealWidget:

public interface IDoesCoolThings {     void DoCool(); }  public abstract class AbstractWidget : IDoesCoolThings {     void IDoesCoolThings.DoCool()     {         Console.Write('I did something cool.');     } }  public class RealWidget : AbstractWidget {  } 

When I instantiate a RealWidget object and call DoCool() on it, the compiler gives me an error saying

‘RealWidget’ does not contain a definition for ‘DoCool’

I can cast RealWidget object to an IDoesCoolThings and then the call will work, but that seems unnecessary and I also lose polymorphism (AbstractWidget.DoCool() will always be called even if i define RealWidget.DoCool()).

I imagine the solution is simple, but I’ve tried a variety of things and for the life of me can’t figure this one out.

  • 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. 2026-05-11T12:57:41+00:00Added an answer on May 11, 2026 at 12:57 pm

    You’re running into the issue because you used explicit interface implementation (EII). When a member is explicitly implemented, it can’t be accessed through a class instance — only through an instance of the interface. In your example, that’s why you can’t call DoCool() unless you cast your instance to IDoesCoolThings.

    The solution is to make DoCool() public and remove the explicit interface implementation:

    public abstract class AbstractWidget : IDoesCoolThings {     public void DoCool()      // DoCool() is part of the abstract class implementation.     {         Console.Write('I did something cool.');     } }  // ...  var rw = new RealWidget(); rw.DoCool();                  // Works! 

    In general, you use EII in two cases:

    • You have a class that must implement two interfaces, each of which contains a member that has an identical name/signature to another member in the other interface.
    • You want to force clients not to depend on the implementation details of your class, but rather on the interface that’s being implemented by your class. (This is considered a good practice by some.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.