What is an Interface

Multiple inheritence in .Net

Microsoft .Net does not support multiple inheritance. The biggest problem with multiple inheritance is that it allows for ambiguity when the compiler needs to find the correct implementation of a virtual method. Microsoft introduce Interface as a solution for multiple inheritance. Microsoft .NET allows you to have a single class in the list of parents , therefore supporting single inheritance, but you are free to implement as many interfaces as you wish.

Interface in C#

An interface is a specification for a set of class members, not an implementation. An Interface is a reference type and it contains only abstract members such as Events, Methods, Properties etc. It contain only declaration for its members and implementation defined as separate entities from classes. It can't contain constants, data fields, constructors, destructors and static members and all the member declarations inside interface are implicitly public.

You can think of an interface as an abstract class that contains only pure virtual functions.The implementation of the methods is done in the class that implements the interface.

Interface sample

interface Student { void getInfo(); } class School : Student { // Explicit interface member implementation: void Student.getInfo() { // Method implementation. } static void Main() { // Declare an interface instance. Student obj = new School(); // Call the member. obj.getInfo(); } }

Difference between the Interface and Class

A Class is a full body entity with members, methods along with there definition and implementation. An Interface is just a set of definition that you must implement in your Class inheriting that Interface. More about..... Class and Interface