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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:53:39+00:00 2026-05-24T21:53:39+00:00

Consider the following example: interface IBase1 { int Percentage { get; set; } }

  • 0

Consider the following example:

interface IBase1
{
   int Percentage { get; set; }
}

interface IBase2
{
   int Percentage { get; set; }
}

interface IAllYourBase : IBase1, IBase2
{
}

class AllYourBase : IAllYourBase
{
   int percentage;

   int Percentage {
      get { return percentage; }
      set { percentage = value; }
   }
}

void Foo()
{
   IAllYourBase iayb = new AllYourBase();
   int percentage = iayb.Percentage; // Fails to compile. Ambiguity between 'Percentage' property.
}

In the example above, there is ambiguity between which Percentage property to call. Assuming the IBase1 and IBase2 interfaces may not be changed, how would I go about resolving this ambiguity in the cleanest, most preferred way?

Update

Based on the responses I was getting for using explicit interface implementation, I want to mention that while this does solve the problem it does not solve it in an ideal way for me because I use my AllYourBase object as an IAllYourBase most of the time, never as an IBase1 or IBase2. This is mostly because IAllYourBase also has interface methods (I failed to detail those in my code snippet above because I thought they were irrelevant) that are implemented by AllYourBase and I want to access those too. Casting back and forth all the time will get very tedious and result in messy code.

I did try one solution that involved defining the Percentage property in IAllYourBase and not using explicit interface implementation, which seemed to get rid of the compiler error at least:

class IAllYourBase : IBase1, IBase2
{
   int Percentage { get; set; }
}

Is this a valid solution?

  • 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-24T21:53:40+00:00Added an answer on May 24, 2026 at 9:53 pm

    Implement explicitly:

    public class AllYourBase : IBase1, IBase2
    {
        int IBase1.Percentage { get{ return 12; } }
        int IBase2.Percentage { get{ return 34; } }
    }
    

    If you do this, you can of course treat your non-ambigous properties just like normal.

    IAllYourBase ab = new AllYourBase();
    ab.SomeValue = 1234;
    

    However, if you want to access the percentage prop this will not work (Suppose it did, which value would be expected in return?)

    int percent = ab.Percentage; // Will not work.
    

    you need to specify which percentage to return. And this is done by casting to the correct interface:

    int b1Percent = ((IBase1)ab).Percentage;
    

    As you say, you can redefine the properties in the interface:

    interface IAllYourBase : IBase1, IBase2
    {
        int B1Percentage{ get; }
        int B2Percentage{ get; }
    }
    
    class AllYourBase : IAllYourBase 
    {
       public int B1Percentage{ get{ return 12; } }
       public int B2Percentage{ get{ return 34; } }
       IBase1.Percentage { get { return B1Percentage; } }
       IBase2.Percentage { get { return B2Percentage; } }
    }
    

    Now you have resolved the ambiguity by distinct names instead.

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

Sidebar

Related Questions

Consider the following example: public interface ITask { void Execute(); } public class LoggingTaskRunner
Consider the following simple RESTEasy (JAX-RS) service: @Path(/example-service) public interface ExampleService { @Path(/ping) @GET
Consider the following example: public class Sandbox { public interface Listener<T extends JComponent> {
Consider the following example: class A: @property def x(self): return 5 So, of course
Consider the following example. I have an interface MyInterface, and then two abstract classes
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider the following example program: next :: Int -> Int next i | 0
Consider the following example: int size = 10, *kk = new int[size]; for (int
Consider the following example: struct Scanner { template <typename T> T get(); }; template
Consider the following code. public interface IFoo { } public class Bar { public

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.