Question about two interfaces derived from the same one.

G

Guest

If I have two interfaces derived from the same one. How do I implement the
methods in my class supporting both interfaces? I would like to have
different implementation for methods in base interface from different
interfaces.
 
V

Vadym Stetsyak

Hello, Roy!

R> If I have two interfaces derived from the same one. How do I implement
R> the methods in my class supporting both interfaces? I would like to have
R> different implementation for methods in base interface from different
R> interfaces

Here is code sample

interface IBase
{
void method();
}

interface IDerived1 : IBase
{
void method();
}

interface IDerived2 : IBase
{
void method();
}

class Implementor : IDerived1, IDerived2
{
void IDerived1.method()
{ }

void IDerived2.method()
{ }
}
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
G

Guest

Vadym,
I got the following 3 compile errors:
'IDerived1.p' in explicit interface declaration is not a member of interface
'IDerived2.p' in explicit interface declaration is not a member of interface
'Implementor' does not implement interface member 'IBase.p'

Where p is a property defined in IBase.

Why?

Thanks.
 
J

Jon Skeet [C# MVP]

Roy said:
I got the following 3 compile errors:
'IDerived1.p' in explicit interface declaration is not a member of interface
'IDerived2.p' in explicit interface declaration is not a member of interface
'Implementor' does not implement interface member 'IBase.p'

Where p is a property defined in IBase.

Why?

From the C# spec:

<quote>
The fully qualified name of an interface member must reference the
interface in which the member was declared.
</quote>

p was *declared* in IBase, not IDerived1 or IDerived2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top