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!
Answer Posted / 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 View All Answers
Why delegate is used in c#?
Why we use get and set method in c#?
What is a cs file?
What is interpolation in programming?
List down the commonly used types of exceptions in .net
Can we have multiple threads in one app domain?
What is the difference between ref & out parameters in c#?
how to prevent a class from being inherited in c#.net?
What is difference between field and property in c#?
What is object array in c#?
What operator means?
Where do we set the min and max pool size for connection pooling?
What is application c#?
Explain nullable types in c#?
How big is an int16?