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 to print labels in windows form in C# .net
What is the difference between Hash Table and Arrays?
Write code for palindrome?
What?s the role of the DataReader class in ADO.NET connections?
Is a valid int value?
What is a streamwriter in c#?
What is the difference between TypeOf, GetType and what are the uses of TypeOf, GetType.
what is uniary operators and binary operators and what is the difference
What is orm in c#?
Can we extend sealed class in c#?
In c#, what will happen if you do not explicitly provide a constructor for a class?
What is firstordefault c#?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)