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
Why we use extension method in c#?
What is the difference between ienumerable and enumerator?
What is the correct way of declaring an xml namespace?
what is boxing and unboxing?can we initialize unboxing directly?
Define Virtual folder?
What is difference between singleton and static class in c#?
If I have more than one version of one assemblies, then how'll I use old version (how/where to specify version number?)in my application?
what is a constructor? What is a destructor?
What are tuples c#?
Why do we overload constructors?
How garbage collection deals with circular references.
Define a partial class?
Where is the main method in c#?
What is the difference between do and while loop?
Explain the difference between proc. Sent by val and by sub?