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

Explain what is an interface in c#?

523


How to use delegates with events?

559


What is anonymous methods in c#?

558


Can abstract class be sealed in c#?

477


What is dbml file in c#?

543






What are callback methods in c#?

506


What is namespace in oops?

494


Can you declare a class or a struct as constant?

549


What is appdomain in c#?

490


What is the difference between CreateObject() and GetObject()?

557


What is hashtable c#?

475


What is response redirect in c#?

483


Explain the use of Mutex in C#?

564


What are native methods?

489


Why do we need nullable types in c#?

691