Interface Definition

Learn to define contracts that enforce consistent behavior across unrelated classes.

Interfaces are types that primarily define a contract. They describe the necessary methods and properties for a type implementing the interface.

We can think of interfaces as a set of rules. If a class implements an interface, it must provide all members the interface defines.

Creating interfaces

Interfaces are reference types. They are defined in the same way as classes, but use the interface keyword. Just like classes, they are internal by default. We can mark an interface as public if we want it to be accessible to external code.