Interface :

May 11, 2011
  • Interface is nothing but an contract of the system which can be implemented on accounts.
  • .Net doesn't support the multiple inheritance directly but using interfaces we can achieve multiple inheritance in .net.
  • An Interface can only contains abstract members and it is a reference type.
  • Interface members can be Methods, Properties, Events and Indexers. But the interfaces only contains declaration for its members.
  • Class which inherits interface needs to implement all it's methods.
  • All declared interface member are implicitly public.
class Program { interface BaseInterface { void BaseInterfaceMethod(); } interface DerivedInterface : BaseInterface { void DerivedToImplement(); } class InterfaceImplementer : DerivedInterface { public void DerivedToImplement() { Console.WriteLine("Method of Derived Interface called."); } public void BaseInterfaceMethod() { Console.WriteLine("Method of Base Interface called."); } } static void Main(string[] args) { InterfaceImplementer er = new InterfaceImplementer(); er.DerivedToImplement(); er.BaseInterfaceMethod(); Console.Read(); } }

Method of Derived Interface called.
Method of Base Interface called.