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 / 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 |
What is the root element of an xml file?
What is the output of TextWriterTraceListener redirected?
What is xml serialization and deserialization in c#?
What are the principles of delegation?
What does readonly mean in c#?
hi, is compulsory .net knowledge need for biztalk server training. if need, how far?.tell me some info abt real time instructors in hyd or other?
Is it possible to have a static indexer in c#?
Are c# generics the same as c++ templates?
What is .cs file in c#?
can we access main() using objects?
How do I create a delegate/multicastdelegate?
What is int tryparse in c#?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)