1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 6 namespaceinterface _ Implicit interface implementation7 {8 //Define Interface 1:ichinesegreeting9 InterfaceichinesegreetingTen { One voidSayHello (); A } - - //Define Interface 2:iamericangreeting the Interfaceiamericangreeting - { - voidSayHello (); - } + - //the Speaker class implements two interfaces: Ichinesegreeting, iamericangreeting + Public classspeaker:ichinesegreeting, iamericangreeting A { at //an implicit interface implementation - Public voidSayHello () - { -Console.WriteLine ("Hi there!"); - } - } in - class Program to { + Static voidMain (string[] args) - { the //Instantiate speaker *Speaker Speaker =NewSpeaker (); $ Panax Notoginseng //Call Chinese greeting way -Ichinesegreeting ichineseg =(ichinesegreeting) speaker; the Ichineseg.sayhello (); + A //Call American Greeting way theIamericangreeting Iamericang =(iamericangreeting) speaker; + Iamericang.sayhello (); - $ /*---------------------------------------------------------------------------------------------------------- -- $ * 1. Final output: Two "Hello" - * 2. Ichineseg/iamericang called the same SayHello () method - ---------------------------------------------------------------------------------------------------------- --*/ the - console.readline ();Wuyi } the } -}
C #-Interface _ Implicit interface implementation