This is again one those typical .NET Interview questions which move around interfaces to confuse the developer.
For providing different implementation you can qualify the method names with interface names as as shown below. A reference to I1 will display "This is I1" and reference to I2 will display "This is I2". Below is the code snippet for the same.
interface I1
{
void MyMethod();
}
interface I2
{
void MyMethod();
}
class Sample : I1, I2
{
public void I1.MyMethod()
{
Console.WriteLine("This is I1");
}
public void
I2.MyMethod()
{
Console.WriteLine("This is I2");
}
}
50 .NET Interview questions and answers
Asked In: Many Interviews |
Alert Moderator