what is Interface in C#

Posted by Ersudeep13 under C# on 4/28/2016 | Points: 10 | Views : 1495 | Status : [Member] | Replies : 1
Interface---->> If a class contain all abstract function then it is known as an interface.Interface do not provide Implementation.They are implemented by the class and defined as seprate entities from class. An Interface represent a contract in that a class that implements an interface must implement every aspect of that interface exactly as it is defined.
In general Interface provides control over the class. we can define feature as small groups of closly related members and can developed enhanced implementation for your interfaceswithout jeoparadizing existing code,thus minimizing compitability problems.
It is also possible to add new feature to any time by developing adding additional interfaces and implementations.Although intrface implementations can evolve, interfaces themselves cannot be changed once published.

An Interface can contain

1) Abstract functions

An Interface can not contain

1)Non-abstract functions

By default interface functions are treated as public and abstract.An Interface can not be instantiated directly. Creating/deriving a new class or other interface from an Interface is compulsary/mandatory in order to provide implementation to abstract function. An interface can itself inherit from multiple interfaces.An Interface is used to implement Multiple inheritance in C#.Net.

Program to implement Interface---

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interface
interface Employee
void GetEmpData();
void DispalyEmpData();

class Manager : Employee
int EmpId;
string EName;
double Bonus, CA;
public void GetEmpData()
Console.Write("Enter Managers Details :-");
EmpId = Convert.ToInt32(Console.ReadLine());
EName = Console.ReadLine();
Bonus = Convert.ToDouble(Console.ReadLine());
CA = Convert.ToDouble(Console.ReadLine());
public void DispalyEmpData()
Console.WriteLine("Manager Id is" + EmpId);
Console.WriteLine("Manager Name is" + EName);
Console.WriteLine("Manager Bonus is" + Bonus);
Console.WriteLine("Manager CA is" + CA);

static void Main(string[] args)

Manager Obj1 = new Manager();


Enter manager Detail is-- 10
Manager Id is:- 10
Manager Name is:- ravi
Manager Bonus is:- 15000
Manager CA is:- 25000


Posted by: Rajnilari2015 on: 4/28/2016 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Please post in Interview Section

Thanks & Regards,
RNA Team

Ersudeep13, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response