Interface Definitions

Interfaces are declared in a similar way to classes, but using the interface keyword, rather than class :

interface IMyInterface
{
    // Interface members.
}

The access modifier keywords public and internal are used in the same way; and as with classes, interfaces are defined as internal by default. To make an interface publicly accessible you must use the public keyword:

public interface IMyInterface
{
// Interface members.
}

The keywords abstract and sealed are not allowed because neither modifier makes sense in the context of interfaces (they contain no implementation, so they can ’ t be instantiated directly, and they must be inheritable to be useful). Interface inheritance is also specified in a similar way to class inheritance. The main difference here is that multiple base interfaces can be used, as shown here:

public interface IMyInterface : IMyBaseInterface, IMyBaseInterface2
{
// Interface members.
}

Interfaces are not classes, and thus do not inherit from System.Object . However, the members of System.Object are available via an interface type variable, purely for convenience. Consider the following program for full implementation.

using System;

namespace ConsoleApplication1
{
    public abstract class MyBase
    {
    }
    internal class MyClass : MyBase
    {
    }
    public interface IMyBaseInterface
    {
    }
    internal interface IMyBaseInterface2
    {
    }
    internal interface IMyInterface : IMyBaseInterface, 
        IMyBaseInterface2
    {
    }
    internal sealed class MyComplexClass : MyClass, 
        IMyInterface
    {
    }
    class Program
    {
        static void Main(string[] args)
        {
            MyComplexClass myObj = new MyComplexClass();
            Console.WriteLine(myObj.ToString());
            Console.ReadKey();
        }
    }
}