Below is my code:
public interface I1 { void method1(); } public interface I2 { void method1(); } class MyClass { static void Main(string[] args) { One one = new One(); } } public class One :I1,I2 { void I1.method1() { Console.WriteLine("This is method1 from Interface 1"); } void I2.method1() { Console.WriteLine("This is method1 from Interface 2"); } }
I have below problems:
I cannot declare methods as Public in the One class, since these are interface methods.
This is only because you are using an explicit interface implementation . Assuming you really need two different implementations, you can make one of them implicit:
public void method1() { Console.WriteLine("This is method1 from Interface 1"); } void I2.method1() { Console.WriteLine("This is method1 from Interface 2"); }
, public, one.method1() . , ( , ).
public
one.method1()
MyClass .
, , , one one.
one
:
One one = new One(); I1 i1 = one; I2 i2 = one; i1.method1(); i2.method1();
((I1)one).method1(); ((I2)one).method1();
. ,
One one = new One(); I1 x = (I1)one; x.method1();
, , One, , , :
One
public class One : I1, I2 { public void method1() { Console.WriteLine("Combined"); } }
3 :
var x = new One(); x.method1(); I1 i1 = x; i1.method1(); I2 i2 = x; i2.method1();
. , , , , #, , , C, . #, , , .
, , .
2 , , , , #;)
, , :
One one = new One(); ((I1)one).method1(); ((I2)one).method1();
and we can have one publication that uses one interface:
public void method1() { ((I1)this).method1(); }
Source: https://habr.com/ru/post/1568311/More articles:using angular.copy to extend a service - javascriptbash: limiting subshells in a for loop with a file list - bashJenkins Cobertura build - NoClassDefFoundError - javaGetting UID of a remote message - javaHow to set a specific location for a string in C # - c #Progress Bar and Reference Worker - vb.netShow thumbnail video using jQuery-File-Upload - phpVB.Net - Updating the progress bar from a background worker - vb.nethttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1568315/backgroundworker-still-needs-to-call-invoke&usg=ALkJrhgX6XWbxq1-5DEZIfA2_81k4Wo86gMaintaining your personal differential with git - gitAll Articles