C# Multiple Interface Inheritance does not allow public access modifier with same name -


so has me perplexed.
suppose 2 interfaces.

public interface {     void foo(); }  public interface b {     void foo(); } 

both of interfaces have function foo, have class provides explicit implementation:

public class alpha : a, b {     // why can't put access modifier here?     // how able hide derived class     void a.foo()     {         console.writeline("a");     }     void b.foo()     {         console.writeline("b");     } } 

and class derived alpha

public class beta : alpha { } 

how make foo private or protected since alpha doesn't allow access modifiers on explicit imlementation, can stop calling:

var = new beta(); (be b).foo(); 

edit

how come when don't explicitly provide implementation can provide access modifier?

public class alpha : a, b {    //why compile?     public void foo()     {         console.writeline("both");     }  } 

since interface a public, class implements a must make methods of a publicly accessible, either implicitly (through public methods) or explicitly. explicit implementations "sort-of" private since can accessed through interface.

in short, there no way "hide" foo - class implements both a , b methods must me made accessible through means.

this true if had one interface - having multiple interfaces method name collision forces make implementations explicit. if had 1 interface, foo either have public or explicit.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -