C# Interfaces

C# Code Snippets Interfaces


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.


Resulting output:


Leave a Reply

Your email address will not be published.

The following GDPR rules must be read and accepted:
This form collects your name, email and content so that we can keep track of the comments placed on the website. For more info check our privacy policy where you will get more info on where, how and why we store your data.

Advertisment ad adsense adlogger