In this code snippet, we will take a look at interfaces in C#.
When I was first learning about interfaces I was given this analogy: “Interfaces are like contracts that specify what a class has to implement”. When a class uses an interface it must implement everything that the interface specifies.
Interfaces are very similar to abstract classes. But a class can only inherit from one other class meanwhile it can implement multiple interfaces. When naming an interface the convention is to start the name with I.
Interfaces can contain: events, indexers, methods, properties
Interfaces can’t contain: constants, types, fields, constructors, operators, finalizers
Let’s have a look at the code below to see how to make an interface.