This article is about C# Simple tutorial for beginners , This is the first 13 piece . Thank you for watching. , Remember to follow me , There are more tutorial articles to follow , thank you .
The environment of this paper is Visual Studio 2019.
One 、 Interface
Interface can be understood as the reserved opening of various objects in life , Specifically used to connect other components .
In programming , It can be understood as a high degree of abstraction from the real world , Just define the characteristics it has 、 function 、 Relationship , Interface .
Two 、 Interface code definition
Use keywords interface Make a statement , Interfaces can contain methods 、 attribute 、 Events and indexers . The interface does not provide a specific implementation . The class implementing the interface is responsible for the concrete implementation of the method property event indexer .
Interfaces can introduce generic keywords in、out, Here's the picture ：
No interface member can be included , under these circumstances , It is only used to represent specific features . But it's not recommended .
3、 ... and 、 Interface features
1. Members in the interface , Access modifiers cannot be used ( Such as public).
2. Interfaces can also be inherited from other interfaces , You can inherit multiple . Use a colon (:) As an inheritance symbol .
3. Interface cannot be instantiated .
4. Interfaces are the highest level abstractions that are more abstract than abstract classes , It's just a definition , There is no implementation .
Four 、 Example
We take... In the family “ fish ” As an example , Description Interface , Interface when writing code , You can use refactoring ：
Or use shortcut keys Ctrl+R,I To quickly generate interfaces . Here's the picture , It's code generated using rapid refactoring ：
Conclusion ： Interface is a difficult knowledge point to master . It's not hard to use , The main difficulty is in defining , Beginners often don't understand , What needs to be put in the interface and what doesn't need to be , Or there are too many members in the interface , Very bloated , This requires continuous learning and training , For details, please refer to my previous high-level articles .
Have a good meal .