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

What is difference between ienumerable and ienumerator in c#?

714


What is a concrete class in c#?

745


Write a program to find the angle between the hours and minutes in a clock

694


What is namespace in oops?

670


What is list collection in c#?

729


How long can loop recorders stay in?

882


How many constructor can a class have?

706


What is the symbol used for in c#?

693


How do you escape in c#?

735


What is string programming language?

620


What is an int in c#?

696


What is a dimensional array?

633


What is the difference between var and dynamic types in c# 4.0?

703


Difference between directcast and ctype.

751


What is lock statement in C#?

741