What is mean by interface?

 An interface contains a group of related functionalities that a class or struct can implement. The interface defines a set of strict rules which need to be implemented when any class implements from that interface. The interface defines only the signature.

interface IEquatable<T>

{

    bool Equals(T obj);

}


Any class or struct that implements the IEquatable<T> interface must contain a definition for an Equals method that matches the signature that the interface specifies.

Key Features of the Interface:

·         Interfaces contain no implementation of methods.

·         Interfaces can contain methods, properties, events, indexers, or any combination of those four member types.

·         An interface can't contain constants, fields, operators, instance constructors, finalizers, or types.

·         Interface members are automatically public, and we can't include any access modifiers.

·         Members also can't be static.

·         To implement an interface member, the corresponding member of the implementing class must be public, non-static, and have the same name and signature as the interface member.

·         Interfaces can inherit from other interfaces.

·         A class or struct can implement multiple interfaces. A class can inherit a base class and also implement one or more interfaces.

Post a Comment

0 Comments