1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 /*----------------------------------------------------------------------------7 * Explicitly implement the interface:8 * 1. A class inherits more than two interfaces9 * 2. Methods with the same name in the interfaceTen * 3. Display the implementation in the class through the "interface. Method ()" Format One * 4. To pass an instantiated object of a class to a different interface object, call the A * is the different interface under the respective methods - * 5. You cannot use any modifiers before explicitly implementing an interface method in a class - * 6. Show that the implemented members are private by default, i.e. they cannot be instantiated through a class the * objects are called directly outside the class, and the correct way to access them is through the class pair - * Like explicit conversion to the corresponding interface, through the interface to access the method - -----------------------------------------------------------------------------*/ - namespaceInterface _ Explicit interface implementation + { - //defining interfaces: Ichinesegreeting + Interfaceichinesegreeting A { at voidSayHello (); - } - - //defining interfaces: Iamericangreeting - Interfaceiamericangreeting - { in voidSayHello (); - } to + //Implementation Interface: Speaker class - Public classspeaker:ichinesegreeting, iamericangreeting the { * //Interface: ichinesegreeting Display implementation $ voidIchinesegreeting.sayhello ()Panax Notoginseng { -Console.WriteLine ("Hi there!"); the } + A //Interface: iamericangreeting Display implementation the voidIamericangreeting.sayhello () + { -Console.WriteLine ("hello!"); $ } $ } - - class Program the { - Static voidMain (string[] args)Wuyi { theSpeaker Speaker =NewSpeaker (); - WuIchinesegreeting ichineseg =(ichinesegreeting) speaker; -Ichineseg.sayhello ();//output "Hello" " About $Iamericangreeting Iamericang =(iamericangreeting) speaker; -Iamericang.sayhello ();//output "" Hello "" - - console.readline (); A } + } the}
C #-Interface _ Explicit interface implementation