What is the Use Of Interfaces?
For example I have a interface as shown below?

Interface IMyInterface
{
public void MyMethod();
}

class MyClass : IMyInterface
{
public void Mymethod()
{
Some Code
}
}

class Program
{
static void Main(string[] args)
{
MyClass obj = new MyClass();
obj.MyMethod();
}
}

Here What is My Question is?

If i remove Interface and run this code, it will executed then what is the Use
of the interface? Can any one give me the solution for this Problem?

Thanks in Advance!



What is the Use Of Interfaces? For example I have a interface as shown below? Interface IMyInter..

Answer / sheetal

Offcourse it works if you remove the interface. What is the
purpose of interface is : if you implementing any interface
you need to define all the methods declare in interface in
your class. In this code snippet implement the interface
and do define method in class and compile the program. It
will give you compile time error.

Interface IMyInterface
{
public void MyMethod();
}

class MyClass : IMyInterface
{
//DO NOT DEFINE MyMethod()
}

Is This Answer Correct ?    6 Yes 3 No

Post New Answer

More C Sharp Interview Questions

Do vs while c#?

0 Answers  


What do you mean by serialization in .NET?

0 Answers   Accenture,


What is the difference between method and constructor in c#?

0 Answers  


how to use caching in our program. why we use it give one example in code

1 Answers  


What is int16?

0 Answers  


To create a localized application which namespaces are necessary?

0 Answers   Siebel,


How to reverse each word in a string using c#?

0 Answers   Infosys,


What is delimiter in c#?

0 Answers  


What is asenumerable in c#?

0 Answers  


Can properties be overloaded in c#?

0 Answers  


What is the difference between namespace and class in c#?

0 Answers  


What is the difference between ienumerable and enumerable?

0 Answers  


Categories