The first section
Interface (interface) is used to define an agreement of a program. The class or structure of the interface should be strictly consistent with the definition of the interface. With this agreement, you can leave the restrictions on the programming language (theoretical). The interface can be inherited from multiple base interfaces, and the class or structure can implement multiple interfaces. The interface can contain methods, attributes, events, and indexers. The interface itself does not provide the implementation of the members it defined. The interface only specifies the membership that implements the interface or interface that the interface must be provided.
The interface is like a template. This template defines how objects must be implemented. The purpose is to let these methods can be referenced as an interface instance. The interface cannot be instantiated. Classs can implement multiple interfaces and are indexed by these implementations. Interface variables can only index instances of classes that implement the interface. example:
Interface iMyexample {string this [int index] {get; set;} EventHandler Even; vide; string point {get; set;}} public delegate Void EventHandler (Object Sender, Event E);
The interface in the above example contains an index this, an event Even, a method Find and a property Point.
The interface can support multiple inheritance. As in the following example, the interface "ICOMBOBOX" inherits from "ITextBox" and "IListbox".
interface IControl {void Paint ();} interface ITextBox: IControl {void SetText (string text);} interface IListBox: IControl {void SetItems (string [] items);} interface IComboBox: ITextBox, IListBox {}
Class and structure can instantiate the interface. As in the following example, class "editbox" inherits class "Control" while inheriting from "iDatabase" and "icontrol".
Interface Idatabase (Binder B); PUBLIC CLASS Editbox: Control, Icontrol, Idatabase; PUBLIC VOID (Binder B) {...}}
In the above code, the "Paint" method comes from the "iControl" interface; "Bind" method is implemented from the "iDatabase" interface and implemented in the "editbox" class as "PUBLIC".
Description:
1, the interface in the C # is defined independently of the class. This is aligned with the C model, and the interface in C is actually an abstract base class.
2, interfaces and classes can inherit multiple interfaces.
3. Category can inherit a base class, the interface does not inherit the class. This model avoids the multi-inheritance problem of C , and the implementation in different base classes in C may conflict. Therefore, this kind of complex mechanism such as virtual inheritance and explicit scope is also no longer needed. The simplified interface model of the C # helps speed up the development of the application.
4. An interface defines a reference type with abstract members. One of the interfaces in C # actually does only exist of a method mark, but there is no code at all. This suggests that you cannot instantiate an interface, you can only instantiate an object derived from the interface.