Multiple interfaces conflicting method names
Nothing happens, application will get compiled and execute properly. There are two ways to implement interface with conflict method name.Example
public interface MyInterface1{
int Add(int i, int j)
}
public interface MyInterface2
{
int Add(int i, int j)
}
Solution 1.
public class MyClass : MyInterface1, MyInterface2{
public int Add(int i, int j)
{
return i + j;
}
}
Solution 2.
public class MyClass : MyInterface1, MyInterface2{
public int Add(int i, int j)
{
return i + j;
}
int MyInterface2.Add(int i, int j)
{
return i + j + 5;
}
}
static void Main(string[] args)
{
MyInterface1 obj1 = new MyClass();
int i = obj1.Add(1, 2);
Console.WriteLine(i);
MyInterface2 obj2 = new MyClass();
int j = obj2.Add(1, 2);
Console.WriteLine(j);
}
Output
38
No comments:
Post a Comment