Introduction to the c # (10) interface (Interfaces)

Source: Internet
Author: User

1.10 interface (Interfaces)

Interface is used to define the contract of a program. With this contract, you can run the programming language restrictions (theoretically ). While the implementation Interface
The class or structure must be strictly consistent with the interface definition. The interface can contain the following members: method, attribute, index, and event. Example :*/

Interface IExample
{
String this [int index] {get; set ;}
Event EventHandler E;
Void F (int value );
String P {get; set ;}
}
Public delegate void EventHandler (object sender, Event e );
/*

The interface in the example contains an index, an event E, a method F, and a property P.
The interface supports multiple inheritance. In the following example, "IComboBox" is inherited from "ITextBox" and "IListBox" at the same time.

*/
Interface IControl
{
Void Paint ();
}
Interface ITextBox: IControl
{
Void SetText (string text );
}
Interface IListBox: IControl
{
Void SetItems (string [] items );
}
Interface IComboBox: ITextBox, IListBox {}
/*

The class and structure can be instantiated on multiple interfaces. In the following example, the class "EditBox" inherits the class "Control" and "IDataBound" and "IControl.
*/

Interface IDataBound
{
Void Bind (Binder B );
}
Public class EditBox: Control, IControl, IDataBound
{
Public void Paint ();
Public void Bind (Binder B ){...}
}
/*

In the above Code, the "Paint" method comes from the "IControl" interface; the "Bind" method comes from the "IDataBound" interface, all are implemented in the EditBox class as "public.

Related Article

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.