When calling methods on a base class from a derived class, should the ‘base’ keyword be used? It seems using the base keyword would increase code readability but for me so far, when I exclude it, there is no affect on code compilation and execution.
Share
You should not use
baseunless you specifically mean “Even if there is a method in this class that overrides the base implementation, I want to call the base implementation and ignore the one on this class”.Using
basebypasses the virtual dispatch mechanism that is so important in polymorphism by causing acallinstruction to be emitted rather thancallvirt.So saying
base.Foo()is very, very different in semantics to sayingthis.Foo(). And you almost always want the latter.