C # example of Interface application,
Official definition: interfaces only contain signatures for methods, properties, events, and indexers.
When a class or struct implements an Interface, it must implement all the members of this Interface definition declaration. One Interface can inherit one or more Base interfaces) in a list containing the base class and interface, the base class must be placed in front of the member that can explicitly implement the interface when a class implements the interface, an explicitly implemented interface member cannot be accessed through an instance of the class and can only be accessed through an instance of the interface.
Namespace CSharpStudy {interface IAddInterface {string IAdd (string a, string B); int IAdd (int a, int B);} class Add {public string Addstr (string a, string B) {return a + B ;}// class Program: IAddInterface. The Add compilation error is in a list containing the base class and interface. The base class must be placed in the previous class Program: Add, IAddInterface {static void Main (string [] args) {Program P = new Program (); IAddInterface IP = new Program (); Console. writeLine (P. IAdd ( "Hello", "World"); Console. writeLine (IP. IAdd (1, 2); Console. writeLine (IP. IAdd ("Hello", "World"); // The interface instance can access the explicitly and implicitly implemented interface member // P. IAdd (1, 2); Compilation error. An explicitly implemented interface member cannot be accessed through an instance of the class and can only be accessed through an instance of the interface. } Public string IAdd (string a, string B) // to implement the interface implicitly, it must be public. {Return a + B;} int IAddInterface. IAdd (int a, int B) {return a + B ;}}