Note that there are some explanatory texts on larger screens.

plurals
  1. POInherited Interface's Method Can't Be Explicitly Declare as "Public"
    primarykey
    data
    text
    <p>might someone have a quick answer for me...</p> <p>in the following entirely useless code, under 'class DuplicateInterfaceClass : MyInterface1, MyInterface2'. </p> <p>Why can't I explicitly write "public string MyInterface2.P()"?<BR> yet "public string P()" and "string MyInterface2.P()" work.</p> <p>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".</p> <pre><code>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()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload