> That's fine. Now if two interfaces accidentally have a method with
> same signature but we want different functional implementaion of both
> the methods. Can we use some different names (say M2 and M3) while
> implementing I1.M1() and I2.M1() so that its more logical for the
> users of class C1.
> <snip>
>
[quoted text clipped - 6 lines]
> No. Users of the class who want to use it "as" a particular interface
> need to cast to that interface.
Maybe I didn't understand the question correctly, but I think he's asking
whether two public methods M2 and M3 that would be used outside the
context of the interface can be used as the implementation for each of the
interface methods as well.
If so, then the answer is basically yes. I mean, you can't alias the
method names or anything like that, but you can just have the interface
methods call some other method directly. So I1.M1() could call M2 and
I2.M1() could call M3.
You're right that when the interface methods are declared explicitly, a
cast is needed to get at them. But I didn't think that's what Mukesh was
asking.
Pete
Jon Skeet [C# MVP] - 10 Jan 2008 08:24 GMT
On Jan 10, 8:20 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
> > No. Users of the class who want to use it "as" a particular interface
> > need to cast to that interface.
[quoted text clipped - 12 lines]
> cast is needed to get at them. But I didn't think that's what Mukesh was
> asking.
I think he was asking about the aliasing side. I *believe* that VB.NET
actually lets you do that. But yes, explicit interface implementation
which calls a public/internal method with a more descriptive name is
an easy way of getting round the limitation.
Jon
Mukesh - 10 Jan 2008 09:55 GMT
> On Jan 10, 8:20 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
> wrote:
[quoted text clipped - 24 lines]
>
> - Show quoted text -
Hi Jon,
You are right. Actually method names for a class should signify the
functionality it provides. Since the method name for the two methods
is same that may be a bit ambiguous for the user using that class. So
I wanted to refine the names in the context of that class to reflect
the implementation functionality.
Thanks for the solution.
Mukesh
Marc Gravell - 10 Jan 2008 08:31 GMT
Aside (for the OP's benefit): what you describe is supported at the IL
level (and VB allows this usage natively), but it isn't possible via
C#. But as Peter observes, it is trivial to just forward the methods
from the explicit implementations.
Marc