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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:07:31+00:00 2026-05-30T17:07:31+00:00

might someone have a quick answer for me… in the following entirely useless code,

  • 0

might someone have a quick answer for me…

in the following entirely useless code, under ‘class DuplicateInterfaceClass : MyInterface1, MyInterface2’.

Why can’t I explicitly write “public string MyInterface2.P()”?

yet “public string P()” and “string MyInterface2.P()” work.

I understand that all interface methods (properties, etc.) are implicitly “public” by default, but my attempt to be explicit in the inheriting class results in an “error CS0106: The modifier ‘public’ is not valid for this item”.

using System;

interface MyInterface1
{
    void DuplicateMethod();

    // interface property
    string P
    {   get;    }
}

interface MyInterface2
{
    void DuplicateMethod();

    // function ambiguous with MyInterface1's property
    string P();
}

// must implement all inherited interface methods
class DuplicateInterfaceClass : MyInterface1, MyInterface2
{
    public void DuplicateMethod()
    {
        Console.WriteLine("DuplicateInterfaceClass.DuplicateMethod");
    }

    // MyInterface1 property
    string MyInterface1.P
    {   get
        {   return ("DuplicateInterfaceClass.P property");  }
    }

    // MyInterface2 method
    // why? public string P()...and not public string MyInterface2.P()?
    string MyInterface2.P()
    {   return ("DuplicateInterfaceClass.P()"); }

}

class InterfaceTest
{
    static void Main()
    {
        DuplicateInterfaceClass test = new DuplicateInterfaceClass();       
        test.DuplicateMethod();     

        MyInterface1 i1 = (MyInterface1)test;
        Console.WriteLine(i1.P);

        MyInterface2 i2 = (MyInterface2)test;
        Console.WriteLine(i2.P());
    }
}
  • 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-30T17:07:32+00:00Added an answer on May 30, 2026 at 5:07 pm

    I have this explicit message from Resharper :
    “The modifier ‘public’ is not valid for explicit interface implementation.”

    But you can do that :

    class DuplicateInterfaceClass : MyInterface1, MyInterface2
    {
     public void DuplicateMethod()
     {
      Console.WriteLine("DuplicateInterfaceClass.DuplicateMethod");
     }
    
     string MyInterface1.P
     { get { return "DuplicateInterfaceClass.P"; } }
    
     string MyInterface2.P()
     { return "DuplicateInterfaceClass.P()"; }
    
     public string P()
     { return ((MyInterface2)this).P(); }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wondered if someone might have some insight into this. jqGrid is quite happy
I have a rather odd scenario here, hoping someone might have some insight. I
So, I´ve got an issue that someone might have solved (or so I hope).
Hopefully a quick one for someone?! I am TOTALLY at a loss. I have
I know this is an open-ended quesiton, but I was hoping someone might have
Hoping someone might have some experience with this. I'm using Apache POI 3.8b4 to
I don't think this is possible, but thought someone might have a nifty idea
I was hoping someone might help with a function that given two parameters: @param
I'm having some strange drawing artefacts that I'm hoping someone might be able to
Can someone give me some info/background info on how I might go about writing

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.