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
Explain what is an interface in c#?
How to use delegates with events?
What is anonymous methods in c#?
Can abstract class be sealed in c#?
What is dbml file in c#?
What are callback methods in c#?
What is namespace in oops?
Can you declare a class or a struct as constant?
What is appdomain in c#?
What is the difference between CreateObject() and GetObject()?
What is hashtable c#?
What is response redirect in c#?
Explain the use of Mutex in C#?
What are native methods?
Why do we need nullable types in c#?