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


Please Help Members By Posting Answers For Below Questions

What is difference between method overriding and method overloading?

619


What is boxing and unboxing in c#?

541


What is asynchronous one-way calls?

622


What is inumerable?

642


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

576






What is javascriptserializer c#?

593


What is deferred execution in c#?

607


What is the use of jit ? Jit (just - in - time) is a compiler which converts msil code to

601


What are strings in c#?

593


What is concrete class in c# with example?

562


What is ienumerator c#?

553


What is a .aspx file?

530


Can abstract classes be final?

593


Explain About delegates

675


Explain briefly the difference between value type and reference type?

645