How to solve this inheritance difficulty?
I use class A
from third-party library. Class has method M
:
public class A
{
public int M(int x)
{
...
}
}
I've written my class B
with method M
:
public class B : A
{
开发者_如何学JAVApublic void M(params int[] xs)
{
}
}
And then in class C
I want to call method M
of parent class A
public class C : B
{
public void M2()
{
int result = M(1);
}
}
But compiler marks this line as error. It tries to use method M
of class B
, that returns void
.
B
?I think that ((A)this).M(1)
would help you. Note that if those methods are virtual/overridden somewhere - things could change.
Thus said, I think that hiding method in such a way is a bad idea that communicating either poor design choices or some hackery. At least I can't think out a way when I really need this.
精彩评论