Shape Definition.
Class shape: icloneable{Object icloneable. Clone (){...}}Class ellipse: Shape{Object icloneable. Clone (){...}}
It is incorrect to define icloneable. clone in ellipse, because even if ellipse implicitly implements the icloneable interface, icloneable still 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
base class list during Shape Definition.
Class shape: icloneable{Object icloneable. Clone (){...}}Class ellipse: Shape{Object icloneable. Clone (){...}}
It is incorrect to define icloneable. clone in ellipse, because even if ellipse implicitly implements the icloneable interface, icloneable still 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 ex
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
all the parent interfaces of the interface, regardless of whether these parent interfaces are listed in the base class table defined by the class. See the following example:
Using System;Interface IControl {Void Paint ();}Interface ITextBox: IControl {Void SetText (string text );}Interface IListBox: IControl {Void SetItems (string [] items );}Interface IComboBox
Shape:icloneable{Object ICloneable.Clone () {...}}Class Ellipse:shape{Object ICloneable.Clone () {...}}It is wrong to define icloneable.clone in ellipse because ellipse implicitly implements the interface icloneable,icloneable still does not appear explicitly in the ellipse-defined base class list.The full 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 ICon
Shape Definition.
Class Shape: ICloneable{Object ICloneable. Clone (){...}}Class Ellipse: Shape{Object ICloneable. Clone (){...}}
It is incorrect to define ICloneable. Clone in Ellipse, because even if Ellipse implicitly implements the ICloneable interface, ICloneable still 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
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
default. In Java, a method definition can carry a public modifier (even if this is not necessary), but in C #, explicitly specifying a public modifier for an interface method is invalid. For example, 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
the base class table of the class definition. Look at the following example:Using System;Interface IControl {void Paint ();}Interface Itextbox:icontrol {void SetText (string text);}Interface Ilistbox:icontrol {void Setitems (string[] items);}Interface Icombobox:itextbox, IListBox {}Here, the interface IComboBox inherits ITextBox and IListBox. The class TextBox not only implements the interface ITextBox, but also implements the parent interface
interfaces cannot include variable members , only properties, events, methods, indexers (only two 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 interface
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
ringsequence:isequence,iring
{Public
Object Add () {...}
public int Insert (object obj) {...}
}
If a class 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:itextb
. In Java, a method definition can carry a public modifier (even if this is not necessary), but in C #, explicitly specifying a public modifier for an interface method is invalid. For example, 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 iContro
to instances of classes that implement this interface. Example:
Interface 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
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
variables can only be indexed to instances of classes that implement this interface. Example:
Interface 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"
carry a public modifier (even if this is not necessary), but in C #, explicitly specifying a public modifier for an interface method is invalid. For example, 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 followi
] {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:
, a method definition can carry a public modifier (even if this is not necessary), but in C #, explicitly specifying a public modifier for an interface method is invalid. For example, 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
=" function onkeypress (){Expandcollapse_checkkey (sectiontoggle0)} "> Interface Overview
The interface can beNamespaceOrClassMember
The interface has the following attributes:
An interface is similar 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 me
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.