Interface in C#

MSDN states that, "An interface defines a set of members, such as properties and procedures, that classes and structures can implement. The interface defines only the signatures of the members and not their internal workings."

This means that an interface is a definition of what an object does, but it doesn’t say how the object does it. Here’s an example to illustrate that "what versus how" difference.


   1: interface IMyInterface

   2: {

   3:     void MethodToImplement();

   4: }

Defining an Interface.
   1: class InterfaceImplementer : IMyInterface

   2: {

   3:     static void Main()

   4:     {

   5:         InterfaceImplementer iImp = new InterfaceImplementer();

   6:         iImp.MethodToImplement();

   7:     }


   9:     public void MethodToImplement()

  10:     {

  11:         Console.WriteLine("MethodToImplement() called.");

  12:     }

  13: }

Using an Interface

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s