Interface in C#

An interface is a template that is defined as a contract and strictly followed by inheriting class. The interface contains signature only means 'What' part of the contract and deriving classes define the 'How' part of the contract.

Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class to define the members. It often helps in providing a standard structure that the deriving classes would follow.

An interface contains only the signatures of methods, properties, events or indexers. Interfaces contain only declaration of the member, default access modifier is public of declaring members of Interface but you can't write with the declaration of members.


interface MyInterface
    void MyMethod();

class DerivedClass : MyInterface
    // Explicit interface member Derived: 
    void MyInterface.MyMethod()
        // Method Derived.

    static void Main()
        // Declare an interface instance.
        MyInterface obj = new DerivedClass();

        // Call the member.

1 comment:

  1. MongoDB concept to create and deploy a highly scalable and performance oriented database.
    To learn follow url :


Please do not enter any spam link in the comment box.

Related Posts

Fatal Error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails.

Problem: Sometimes, we get the following error when trying to make a connection in Rails.  FATAL ERROR: Peer authentication failed for us...