We learned interface, the interface, which is a bit like the abstract class, but they also have some differences, such as the class cannot be multiple inheritance but the interface can inherit multiple.
An interface contains only the signature of a method, delegate, or event and property (the member The interface contains), and cannot contain a field (because the field contains data). The implementation of the method is done in the class of the "inherited" interface, which can contain access modifiers only and default to public, an interface that can inherit from one or more base interfaces, and an interface similar to an abstract base class: Any non-abstract type that inherits an interface must implement all members of the interface; When a base type list contains a base class and an interface, the base class must be the first item in the list, and the class that implements the interface can explicitly implement the members of the interface, which shows that the implemented members cannot be accessed through the instance of the class, but only through the interface instance; A class or struct can inherit multiple interfaces, and when a class or struct inherits an interface, only the method name and signature are inherited, because the interface itself does not contain an implementation; interface and interface members are abstract (but do not write the abstract keyword); interfaces do not provide a default implementation; An interface is a plan that defines a series of rules and tasks for you. But not to achieve it)
Here is an example of a interface:
interface
sampinterface1
{
string
this[ int index]
{
get;
set
}
event EventHandler Event;
void find ( int value );
//Note there is no
{
}
string Po
int
{
get;
set
}
}
The above interface defines an index of this, a practice event, a method of find and a property point.
The following code is also a good illustration of this.
public interface sampineterface:sampineterface1{
pravite int a=1;
void find (int value)
{
A+=value;
}
Event EventHandler event;
protected void OnEvent ()
{
if (event=null)
{return Event (this. System.EventAgrs.Empty;)}
}
}
C # interface