471,336 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

Question about two interfaces derived from the same one.

Roy
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.
Feb 17 '06 #1
3 1204
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
Feb 17 '06 #2
Roy
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.
"Vadym Stetsyak" wrote:
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

Feb 17 '06 #3
Roy <Ro*@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 17 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Shawn Casey | last post: by
8 posts views Thread by Shaun C Farrugia | last post: by
17 posts views Thread by Picho | last post: by
14 posts views Thread by Daniel Billingsley | last post: by
7 posts views Thread by Ant | last post: by
9 posts views Thread by Sean Kirkpatrick | last post: by
8 posts views Thread by ^MisterJingo^ | last post: by
7 posts views Thread by jason | last post: by
1 post views Thread by Larry | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.