C# - Inheritance from method to method within a class?
Is it possible to inherit a method within a class?
Or does it always need to be parent class inheriting child class?For example:
A class called make_chart
Has:
public void style_Chart(Chart chartName,....)
{
}
Can I then inherit style_Chart into a new method called style_Chart2?
So开发者_如何学Cmething like this:
public void style_Chart2: style_Chart(new parameter)
{
}
Within the same type, you would just invoke it:
public void style_Chart2()
{
style_Chart({some parameters});
}
If you are dealing with sublasses, you might also consider virtual
/ base
/ override
. There is a chaining syntax, but it only applies to constructors ( : base(...)
or : this(...)
).
I think you just want method overloading
public void style_Chart(Chart chartName) {
}
public void style_Chart(Chart chartName, new parameter) {
style_Chart(chartName);
//now do things with new parameter
}
精彩评论