Interface

Multiple inheritance is not supported by c#. Instead of that we use interfaces for avoiding ambiguity in C++ , where the object of the class doesn’t know which method to call if the base classes have two methods of the same name.
interfaces are defined in parent and implemented by derived class it have indexers, methods and properties.

for example:


interface Newinterface
{
void Mymethod();
}

interfaces are declared with keyword 'Interface' .

using System;

interface BaseInterface
{
void BaseToImplemen();
}

interface Childinterface:  BaseInterface
{
void childToImplement();
}

class Newchild : Childinterface
{
static void Main()
{
InterfaceImplementer iImp = new InterfaceImplementer();
iImp.childToImplement();
iImp.BaseToImplemen();
}

public void childToImplement()
{
Console.WriteLine("childToImplement() called.");
}

public void BaseToImplemen();
{
Console.WriteLine("BaseToImplemen();called.");
}
}

Follow

Get every new post delivered to your Inbox.