C# 可以从派生类调用基类属性
我有一个基类,其属性具有 setter 方法。有没有办法从派生类调用基类中的 setter 并为其添加更多功能,就像我们使用 base 关键字覆盖方法一样。
抱歉,我应该添加一个例子。这是一个例子。希望我做对了:
public class A
{
public abstract void AProperty
{
set
{
// doing something here
}
}
}
public class B : A
{
public override void AProperty
{
set
{
// how to invoke the base class setter here
// then add some more stuff here
}
}
}
I have a base class with a property which has a setter method. Is there a way to invoke the setter in the base class from a derived class and add some more functionality to it just like we do with overriden methods using the base keyword.
Sorry I should have added an example. Here is an example. Hope I get it right:
public class A
{
public abstract void AProperty
{
set
{
// doing something here
}
}
}
public class B : A
{
public override void AProperty
{
set
{
// how to invoke the base class setter here
// then add some more stuff here
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:修改后的示例应该演示调用的顺序。编译为控制台应用程序。
EDIT: the revised example should demostrate the order of invocations. Compile as a console application.