appear in the base class list defined by ellipse.
The full name of an interface member must correspond to the member defined in the interface. In the following example, the execution body of the explicit interface member of Paint must be written as iControl. Paint.
Using system;Interface iControl{Void paint ();}Interface itextbox: iControl{Void settext (string t
does not explicitly appear in the base class list defined by ellipse.
The full name of an interface member must correspond to the member defined in the interface. In the following example, the execution body of the explicit interface member of Paint must be written as iControl. Paint.
Using system;Interface iControl{Void paint ();}Interface itextbox: iControl
ArticleDirectory
1. Public method implementation Interface Method
2. Private methods cannot implement interface methods
3. Implement special interface methods (1)
4. Implement special interface methods (2)
5. Conclusion
All the icons in this article are for personal understanding (refer to the metadata storage method in assembly), which may be different from the actual situation. Green indicates the public method, and red indicates the private method.
This article u
following example shows how to implement interfaces using classes. ISequence is a queue interface that provides the Add () method for adding objects to the end of the queue. IRing is a circular table interface, the Insert (object obj) method is provided to Insert objects into the ring, and the Insert position is returned by the method. RingSquence class implements the ISequence and IRing interfaces.
Using System;Interface ISequence {Object Add ();}Interface ISequence {Object Add ();}Interface I
name of the interface member must correspond to the member defined in the interface. As in the following example, the explicit interface member execution body of Paint must be written as IControl.Paint.Using System;Interface IControl{void Paint ();}Interface Itextbox:icontrol{void SetText (string text);}Class Textbox:itextbox{void IControl.Paint () {...}void Itextbox.settext (string text) {...}}A class that implements an interface can explicitly impl
in the base class list defined by Ellipse.
The full name of an interface member must correspond to the member defined in the interface. In the following example, the execution body of the explicit interface member of Paint must be written as IControl. Paint.
Using System;Interface IControl{Void Paint ();}Interface ITextBox: IControl{Void SetText (string text );}
If the class implements two interfaces and these two interfaces contain members with the same signature, implementing this member in the class will result in both interfaces using this member as their implementation. For example:Interface iControl
{
Void paint ();
}
Interface isurface
{
Void paint ();
}
Class sampleclass: iControl, isurface
{
// Both isurface. Paint and
, the following C # interface will generate a compilation error.
Interface ishape {public void draw ();}
The following example defines an interface named iControl, which contains a member method "paint:
Interface iControl {Void paint ();}
In the following example, the interface iinterface inherits from two basic interfaces, ibase1 and ibase2:
Interface iinterface: ibase1, ibase2 {Void Method1 ();V
interface that provides a member method for adding objects to the end of the queue, add (), IRing as a looping table interface, provides a way to insert objects into the ring (object obj), and the method returns the inserted position. The class Ringsquence implements interface Isequence and interface iring.Using System;Interface Isequence {Object Add ();}Interface Isequence {Object Add ();}Interface IRing {int Insert (object obj);}Class Ringsequence:isequence, IRing{public Object Add () {...}pu
properties for the example above)3 The class implementing the interface must be implemented in strict accordance with the definition of the interface4 implementing an interface can be implemented implicitly and explicitlyFor example:Interface IControl//interface 1{void Paint ();}Interface ISurface//interface 2{void Paint ();}Note: Both of these interfaces contain the method paint (), which must be explicitly implemented in the following implementatio
I use a custom list control. Inherits caknsinglestylelistbox.
// ------------------------------------------------------ Header file ------------------------------------------------# Ifndef _ cmysinglestylelistbox __# DEFINE _ cmysinglestylelistbox __
# Include # Include
Class cControl;Class cfbsbitmap;Class cmaxicon; // It is a custom image class.
Class cmysinglestylelistbox: Public caknsinglestylelistbox{Public:Cmysinglestylelistbox (cControl * acontrol );Virtual ~ Cmysinglestylelistbox ();Pro
implements an interface, the class implicitly inherits all the parent interfaces of the interface, regardless of whether the parent interfaces are listed in the base class list of the class declaration.
Using System;
Interface icontrol
{
void Paint ();
}
Interface Itextbox:icontrol
{
void SetText (string text);
}
Class Textbox:itextbox
{public
void Paint () {...}
public void SetText (string text) {...}}
In this case, the class textbox not onl
following C # interface will generate a compilation error.
Interface ishape {public void draw ();}
The following example defines an interface named iControl, which contains a member method "paint:
Interface iControl {Void paint ();}
In the following example, the interface iinterface inherits from two basic interfaces, ibase1 and ibase2:
Interface iinterface: ibase1, ibase2 {Void Method1 ();Void m
[int Index] {Get; set ;}Event eventhandler even;Void find (INT value );String point {Get; set ;}}Public Delegate void eventhandler (Object sender, event E );
The interface in the preceding example contains an index this, an event even, a method find, and an attribute point.
The interface supports multiple inheritance. In the following example, the interface "icombobox" inherits from "itextbox" and "ilistbox" at the same time.
Interface iControl
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 InterfaceThe 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
IMyExample {String this [int index] {get; set ;}Event EventHandler Even;Void Find (int value );String Point {get; set ;}}Public delegate void EventHandler (object sender, Event e );
The interface in the preceding example contains an index this, an event Even, a method Find, and an attribute Point.
The interface supports multiple inheritance. In the following example, the interface "IComboBox" inherits from "ITextBox" and "IListBox" at the same time.
Interface
compilation error.
Interface IShape {public void Draw ();}
The following example defines an interface named IControl, which contains a member method "Paint:
Interface IControl {Void Paint ();}
In the following example, the interface IInterface inherits from two basic interfaces, IBase1 and IBase2:
Interface IInterface: IBase1, IBase2 {Void Method1 ();Void Method2 ();}
Interfaces can be implemented by class
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, ILis
# interface will generate a compilation error.
Interface ishape {public void draw ();}
The following example defines an interface named iControl, which contains a member method "paint:
Interface iControl {
Void paint ();
}
In the following example, the interface iinterface inherits from two basic interfaces, ibase1 and ibase2:
Interface iinterface: ibase1, ibase2 {
Void Method1 ();
Void method2 ()
to an abstract base class: any non-Abstract type that inherits an interface must implement all the members of the interface.
The interface cannot be instantiated directly.
Interfaces can contain events, indexers, methods, and attributes.
The interface does not contain the implementation of methods.
Classes and structures can be inherited from multiple interfaces.
The interface itself can be inherited from multiple interfaces
Explicit interface implementation
If the class implements two in
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.