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
Explain the process of Serialization?
if we are updating a database using thread, and mean while application crashes or thread being aborted then what will happen in Database? Rollback or Database will be updated? Please explain with different scenario.
What is the difference between double and decimal in c#?
How do you create user defined data types in c#?
Is inheritance possible in c sharp?
What is difference between for and foreach in c#?
The int maps to which C# keyword in .NET type?
What are the advantages of properties in c#?
What is a boolean c#?
Explain states of a thread in c#?
What is a collection class in c#?
What is the different types of private assembly and shared assembly?
What is difference between constants and readonly in c#?
What are the basic string operations? Explain.
What are the advantages of using delegates in c#?