An interface contains only the signatures of methods, events, indexers or properties. When a class or struct implements the interface then that class/struct must implement the members of the interface that are specified in the interface definition.
interface IEquatable<T>
{
bool Equals(T obj);
}
An interface cannot contain fields and members are automatically public in interface as well and an interface can inherit from one or more base interfaces. When a base type list contains a base class and interfaces, the base class must come first in the list.
A class that implements an interface can explicitly implement members of that interface. An explicitly implemented member cannot be accessed through a class instance, but only through an instance of the interface.
Interfaces can inherit other interfaces. It is possible for a class to inherit an interface multiple times, through base classes or interfaces it inherits. In this case, the class can only implement the interface one time, if it is declared as part of the new class. If the inherited interface is not declared as part of the new class, its implementation is provided by the base class that declared it. It is possible for a base class to implement interface members using virtual members; in that case, the class inheriting the interface can change the interface behavior by overriding the virtual members.
it was necessary to incorporate some other method so that the class can inherit the behavior of more than one class, avoiding the problem of name ambiguity that is found in C++. With name ambiguity, the object of a class does not know which method to call if the two base classes of that class object contain the same named method.
Interfaces Overview
An interface has the following properties:
-
An interface is like an abstract base class: any non-abstract type inheriting the interface must implement all its members.
-
An interface cannot be instantiated directly.
-
Interfaces can contain events, indexers, methods and properties.
-
Interfaces contain no implementation of methods.
-
Classes and structs can inherit from more than one interface.
-
An interface can itself inherit from multiple interfaces.