If there are 2 interface IParentInterface &
IChildInterface as follows.

interface IParentInterface
{
void InterfaceMethod();
}

interface IChildInterface : IParentInterface
{
void InterfaceMethod();
}

Both the interface contains method with same name
InterfaceMethod().

How InterfaceMethod() will be handled in IChildInterface as
its deriving IParentInterface

Answer Posted / sagar

using explicit type casting this scenario is possible.

interface IParentInterface
{
void InterfaceMethod();
}

interface IChildInterface : IParentInterface
{
void InterfaceMethod();
}
class Parent : IChildInterface
{
void IParentInterface.InterfaceMethod()
{
Console.WriteLine("Parent Interface");
}
void IChildInterface.InterfaceMethod()
{
Console.WriteLine("Child Interface");
}
static void Main()
{
Parent p = new Parent();
IParentInterface i1 = p;
IChildInterface i2 = p;
i1.InterfaceMethod();
i2.InterfaceMethod();
Console.ReadLine();

}
}

Is This Answer Correct ?    14 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why we use extension method in c#?

708


What is the difference between ienumerable and enumerator?

685


What is the correct way of declaring an xml namespace?

661


what is boxing and unboxing?can we initialize unboxing directly?

711


Define Virtual folder?

822


What is difference between singleton and static class in c#?

701


If I have more than one version of one assemblies, then how'll I use old version (how/where to specify version number?)in my application?

717


what is a constructor? What is a destructor?

762


What are tuples c#?

718


Why do we overload constructors?

707


How garbage collection deals with circular references.

656


Define a partial class?

684


Where is the main method in c#?

758


What is the difference between do and while loop?

689


Explain the difference between proc. Sent by val and by sub?

702