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

What is difference between static and constant variable?

0 Answers  


Which function is the entry point for a DLL in MS Windows 3.1?

0 Answers   3i Infotech,


What is the example of predicate?

0 Answers  


How do you encapsulate in c#?

0 Answers  


What is returned if you pass the value 12.34 to the parsefloat () function?

0 Answers  






Is array passed by reference in c#?

0 Answers  


how to implement singelton in C# & its uses?

1 Answers   TCS,


how encapsulation is implemented in c#

0 Answers   Cognizant,


How you will handle session when deploying application in more than a server? Describe session handling in a webform, how does it work and what are the limits?

3 Answers   Microsoft,


What is public, private, protected, internal and internal protected?

0 Answers   QuestPond,


who is a protected class-level variable available to?

0 Answers   Siebel Systems,


In a site to turn off cookies for one page which method is followed?

0 Answers   Siebel,


Categories