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
What is difference between ienumerable and ienumerator in c#?
What is a concrete class in c#?
Write a program to find the angle between the hours and minutes in a clock
What is namespace in oops?
What is list collection in c#?
How long can loop recorders stay in?
How many constructor can a class have?
What is the symbol used for in c#?
How do you escape in c#?
What is string programming language?
What is an int in c#?
What is a dimensional array?
What is the difference between var and dynamic types in c# 4.0?
Difference between directcast and ctype.
What is lock statement in C#?