---
title: "Interface"  
description: "InterfaceIn this blog I’m explaining Interface.An interface looks like a class, but has no implementation.  The only thing it contains are declaration"  
author: "Anchal Kesharwani"  
published: 2014-08-12  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/676/interface  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Interface

## Interface

In this blog I’m explaining Interface.

An interface looks like a class, but has no [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp). The only thing it contains are declarations of events, indexers, methods and/or properties. The reason interfaces only provide declarations is because they are inherited by classes and structures, which must provide an implementation for each interface member declared Interfaces in C # provide a way to achieve runtime [polymorphism](https://www.mindstick.com/articles/1827/objective-c-polymorphism) or provide overridden property of polymorphism. Interface allow to [derived class](https://answers.mindstick.com/qa/30686/what-is-a-base-class-and-derived-class) it must be override with same signature and parameter. Interfaces are a powerful [programming](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) tool because they let you separate the [definition](https://yourviews.mindstick.com/view/70598/false-furore-over-the-leadership-definition-statement-of-army-chief-bipin-rawat) of objects from their implementation.

## Benefits of Interface

· Interfaces are better than base classes because you can define a single implementation that can implement [multiple interfaces](https://www.mindstick.com/interview/2599/can-you-inherited-multiple-interfaces).

· Interfaces are useful when you cannot use class inheritance. For example, structures cannot inherit from classes, but they can implement interfaces.

· This two classes has the same function name with different body.

· Interfaces are better in situations in which you do not have to inherit implementation from a [base class](https://www.mindstick.com/blog/116/base-class-initilization).

·

## Example

using System;

namespace InterfaceDemo

{

interface IMessage // create interface using interface keyword

{

void getMessage(string msg); // declare a method for get Message

void showMessage();

}

class InterfaceDemoImplementation : IMessage // [implement interface](https://www.mindstick.com/forum/159835/how-to-implement-interface-in-java-please-provide-a-sample)

{

string getStringMessage; //declare variable for getting message

public void getMessage(string msg) //interface method must override

{

getStringMessage = msg;

}

public void showMessage() //interface method

{

Console.WriteLine(getStringMessage);

}

}

class Demo

{

static void Main(string[] args)

{

InterfaceDemoImplementation interfaceDemo = new InterfaceDemoImplementation(); // create instance of InterfaceDemoImplementation & use the interface

interfaceDemo.getMessage("This Demo for understand Interface");

interfaceDemo.showMessage();

Console.ReadKey();

}

}

}

---

Original Source: https://www.mindstick.com/blog/676/interface

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
