c# interface usage

The characteristics of the interface:
1. The interface is similar to the abstract base class: any non-abstract type that inherits the interface must implement all the members of the interface
2. The interface cannot be instantiated directly
3. The interface can contain time events, indexers, methods and properties
4. The interface does not contain the implementation of the method
5. Classes and structures can inherit from multiple interfaces
6. The interface itself can inherit from multiple interfaces
When C# declares an interface, use the interface keyword, the syntax is as follows:

Modifier interface interface name: inherited interface list (not required)
{ interface content; } Note: When declaring an interface, except for the interface keyword and interface name, all others are optional. You can use new, public, protected, Modifiers such as internal, and private declare interfaces, but interface members must be public. Declare an interface as follows:





interface Myinterface
{
 string ID 
 {
   get;
   set;
 }
 string Name
 {
   get;
   set;
 }
void show();
 {
   Console.WriteLine(“编号:\t 姓名”);
   Console.WriteLine(ID+Name);
 }
}

So, how to implement and inherit the interface?
When inheriting an interface, the inherited class needs to implement all the properties and methods in the interface (not all)

waiting for update…

Guess you like

Origin blog.csdn.net/weixin_41590778/article/details/129475912