C # Interface Usage,
1. Interface: an interface, like an abstract class, also represents a rule. Once this rule is used, relevant methods must be implemented. For the C # language, because it can only inherit from one parent class, it is better to use interfaces if multiple rules need to be implemented. 2. interface Definition interface name {method declaration;} 3. If multiple methods with the same name exist in different interfaces, you must explicitly specify the interface name, for example: 4. The use of interfaces can also achieve polymorphism. The Code is as follows: class Program {static void Main (string [] args) {// provides three classes, list of completed salary calculation <ICalu> list = new List <ICalu> (); list. add (new Boss (); list. add (new Clert (); list. add (new Clert (); list. add (new Customer (); foreach (ICalu emp in list) {emp. calu (); // polymorphism} class Boss: ICalu {public void Calu () {Console. writeLine ("Calculate boss salary") ;}} class Customer: ICalu {public void Calu () {Console. writeLine ("Calculate customer salary") ;}} class Clert: ICalu {public void Calu () {Console. writeLine ("Calculate employee salary") ;}} interface ICalu {void Calu () ;}5. interface Application Example 6. interface demousing System; using System. collections. generic; using System. linq; using System. text; namespace ConsoleApplication1 {class Program {static void Main (string [] args) {List <IShow> list = new List <IShow> (); list. add (new Map (); list. add (new Voice (); list. add (new Video (); list. add (new ThreeD (); foreach (IShow ishow in list) {ishow. show () ;}} interface IShow {void Show ();} public class Map: IShow {public void Show () {Console. writeLine ("Show image") ;}} public class Voice: IShow {public void Show () {Console. writeLine ("Playing Sound") ;}} public class Video: IShow {public void Show () {Console. writeLine ("Show video") ;}} public class ThreeD: IShow {public void Show () {Console. writeLine ("3D interaction ");}}}