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.

Example

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.
        obj.MyMethod();
    }
}



1 comment:

  1. MongoDB concept to create and deploy a highly scalable and performance oriented database.
    To learn follow url : http://www.codefari.com/2015/02/mongodb-overview.html

    ReplyDelete

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

Related Posts

What is the Use of isNaN Function in JavaScript? A Comprehensive Explanation for Effective Input Validation

In the world of JavaScript, input validation is a critical aspect of ensuring that user-provided data is processed correctly. One indispensa...