Click here to Skip to main content
15,851,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
interface A
{
void show();
}

interface B
{
void show();
}


C#
class C : A, B
        {

            public void show()
            {

            }

            public void show()
            {

            }

        }
Posted
Updated 12-Nov-15 20:29pm
v2

Here is how class C need to be implement both interfaces:

C#
class C : A, B
        {
            public void A.show()
            {// Some Code
            }

            public void B.show()
            {// Some Code
            }
        }
 
Share this answer
 
If a class implements two interfaces with the same method define in it, then in effect there is only one method, and they are not distinguishable. And if two methods has the same return type - it is simply a compilation error.

Though you can do something like (implementing the interface explicitly),
C#
class C : A, B
{
    public void A.show()
    {
    }
    
    public void B.show()
    {
    }
}


Read the MSDN documentation: https://msdn.microsoft.com/en-us/library/ms173157.aspx[^]
And a quite good article: http://www.c-sharpcorner.com/UploadFile/rohatash/inherit-multiple-interfaces-with-the-same-method-name-in-C-Sharp/[^]

-KR
 
Share this answer
 
Comments
BillWoodruff 13-Nov-15 7:14am    
If you define C as inheriting from Interfaces A, B : your code will not compile unless you implement A.Show() and B.Show()

This is not an option.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900