What Are C# Interfaces?

An interface defines a contract that all classes that inherit from the interface must follow. This contract contains the signatures of methods, properties, events or indexers that the developer must create in their class that inherits from the interface. The developer can count on these contract pieces being available to them.

The interface only defines what must be included but doesn’t implement them and it is the responsibility of the class inheriting from the interface to implement the properties, methods, and events. An interface cannot contain constants, fields, operators, finalizers, constructors, or types. Interface members are always public and cannot include access modifiers or be static.

Microsoft recommends that you preface the name of your interfaces with the capital letter “I”.

        interface ICars
            string GetModel();
            int GetYear();