考虑以下代码:
public class Vehicle
{
public void StartEngine()
{
// Code here.
}
}
public class CityBus : Vehicle
{
public void MoveToLocation(Location location)
{
////base.StartEngine();
this.StartEngine();
// Do other stuff to drive the bus to the new location.
}
}
有什么区别吗this.StartEngine();
and base.StartEngine();
,除了在第二种情况下,StartEngine
方法不能移动到或重写CityBus
班级?对性能有影响吗?
没有区别,StartEngine() 不是虚拟的。您不应该使用 base,以防您重构它以使其虚拟。性能差异是不可测量的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)