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 a dbml?

0 Answers  


How to do and Apply Themes to Datagrid,Lable,Textbox,etc., in C#.NET 2005 Windows Application? (like who we will do themes in ASP.NET using .CSS and .SKIN files). Urgent!!

0 Answers  


What is the purpose of reserved word using in c#?

0 Answers  


What is encapsulation in csharp?

0 Answers  


wt is namespace? wt is the use?

12 Answers  






What is a hashset c#?

0 Answers  


Why are local variables stored in stack?

0 Answers  


What is the advantage of dependency injection?

0 Answers  


What is Named parameter in C#?

0 Answers  


How many parameters can a method have c#?

0 Answers  


What are the different types of assembly?

0 Answers  


Can you pass value types by reference to a method?

0 Answers  


Categories