namespace IEnumerableTest
{ /** * * The class that implements the interface must contain the implementation code of all members of the interface, and they are all public. There are two ways to implement interface members: implicit implementation and explicit implementation. * * * */ interface Interface1 { void DoSimple1(); void DoSimple2(); } class ShowTest : Interface1 { /** * * For the members of the show implementation, they can only be accessed through the interface, not the class object. * Note It is not necessary to add keywords such as public and private when displaying the interface method. * * * * */ //Display implementation // void Interface1.DoSimple1() //{ // Console.WriteLine("DoSimple1");
//} // void Interface1.DoSimple2() //{ // Console.WriteLine("DoSimple2"); //} /** * * Implicitly implemented members can be accessed either through a class object instance or Can be accessed through the interface * * * * */ //Implicit implementation public void DoSimple1() { Console.WriteLine("DoSimple1"); } public void DoSimple2() { Console.WriteLine("DoSimple2"); } static void Main() { Interface1 s = new ShowTest(); s.DoSimple1();
s.DoSimple2();
ShowTest t = new ShowTest();
t.DoSimple1();
t.DoSimple2(); Console.ReadKey(); } }}
{ /** * * The class that implements the interface must contain the implementation code of all members of the interface, and they are all public. There are two ways to implement interface members: implicit implementation and explicit implementation. * * * */ interface Interface1 { void DoSimple1(); void DoSimple2(); } class ShowTest : Interface1 { /** * * For the members of the show implementation, they can only be accessed through the interface, not the class object. * Note It is not necessary to add keywords such as public and private when displaying the interface method. * * * * */ //Display implementation // void Interface1.DoSimple1() //{ // Console.WriteLine("DoSimple1");
//} // void Interface1.DoSimple2() //{ // Console.WriteLine("DoSimple2"); //} /** * * Implicitly implemented members can be accessed either through a class object instance or Can be accessed through the interface * * * * */ //Implicit implementation public void DoSimple1() { Console.WriteLine("DoSimple1"); } public void DoSimple2() { Console.WriteLine("DoSimple2"); } static void Main() { Interface1 s = new ShowTest(); s.DoSimple1();
s.DoSimple2();
ShowTest t = new ShowTest();
t.DoSimple1();
t.DoSimple2(); Console.ReadKey(); } }}