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
How to find type of variable?
If the original method is not static you can declare an override method to be static or not?
Can we inherit private members of class in c#?
What is array collection?
What is an inheritance ?Give an example in which inheritance is used?
Define delegate?
Is list immutable in c#?
What is xslt in c#?
Are tuples mutable c#?
How does foreach loop work in c#?
What is the difference between static class and abstract class in c#?
Is c sharp and c# are same?
What are the differences between system.string and system.text.stringbuilder classes?
What is binary search tree in data structure?
Which is faster hashtable or dictionary?