C# ClassesLesson 33Free preview
C# Interface
This lesson is part of C# · All levels
Summary
Interface defines a contract as a set of methods without storing data in it. A class can implement multiple interfaces at once, thus being a solution to the single inheritance limitations in C#. The interface also allows explicit implementation to control the method name so as not to penetrate the class.
Key points
- Interface is defined by the keyword interface and is conventionally preceded by a capital I.
- The class implements the interface using the colon mark and must fill out the entire method.
- A class can implement multiple interfaces at once.
- Since C#8, the interface can contain default methods that already contain code and get-only properties.
- The interface doesn't have a field instance because it's meant to split contracts, not data.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.