First, create a new interface class
Using system;using system.collections.generic;using system.linq;using system.web;///<summary>///InterF Summary description/ </summary>public class interf{Public interface Hide { string Show (); } Public interface display { string Show ();} }
Second, new interface implementation class, Hide.cs and Display.cs
A summary description of the using system;using system.collections.generic;using system.linq;using system.web;///<summary>///Speaker </summary>public class hide:interf.hide{Public string Show () { return "implicit interface"; }}
Using system;using system.collections.generic;using system.linq;using system.web;///<summary>///Speaker1 The summary description ///</summary>public class display:interf.display{string InterF.display.show () { return ' Display interface "; }}
Third, create a new default.aspx file
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;public partial class default3:system.web.ui.page{ protected void Page_Load (object sender, EventArgs e) { interf.hide c = new Hide (); C.show (); Hide S = new Hide (); S.show (); Label1.Text = s.show () + c.show (); Interf.display C1 = new display (); C1.show (); Label2.Text = C1.show (); The following wording will cause a compilation error error "Petshop.speaker" does not contain the definition of "Speak" //display s1 = new display (); S1. Speak (); }}
Iv. Summary: The difference between the display interface and the implicit interface
<1> implicitly implements interfaces and classes are accessible to display implementations only interfaces can access.
<2> Display Implementation Benefits
1: Hidden Code implementation function
2: In systems that use interface access, callers can only be accessed through an interface call rather than the underlying class, which facilitates security
In summary: When a class or struct inherits an interface, it means that the class or struct provides an implementation for all members defined by that interface. The interface itself does not provide any functionality that a class or struct can inherit in a way that inherits the functionality of the base class. The base class implements the interface, and the derived class inherits the implementation
Shows the difference between an interface and an implicit interface: