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
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / vijay
In this scenario,
Whenever the child interface is called, by default
InterfaceMethod() of childe interface is gets called.
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / anurag
use
void IChildInterface.InterfaceMethod(){}
don't use access modifier with explicit method.
Is This Answer Correct ? | 2 Yes | 4 No |
How is a loop recorder monitored?
How many types of namespaces available in version4?
What is the use of properties window?
What is a int in c#?
Which is more efficient for loop or while loop?
What is the signature of a method?
What is system predicate?
What are the Types of optimization and name a few and how do u do?
Explain the concepts of cts and cls(common language specification).
What is a console?
Does c# do array bounds checking?
What is xml c#?