Shows the difference between an interface and an implicit interface:

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.