Name
MyBase Keyword
Syntax
MyBase
Description
Provides a reference to the base class from within a derived class. If you want to call a member of the base class from within a derived class, you can use the syntax:
MyBase.MemberNamewhere MemberName is the name of the
member. This will resolve any ambiguity if the derived class also has
a member of the same name.
Rules at a Glance
MyBasewill call through the chain of inherited classes until it finds a callable implementation. For example, in the code:Public Class CTestClass ... End Class Public Class CTestClass2 Inherits CTestClass Public Function ShowType( ) As Type Return Mybase.GetType End Function End Classthe call to ShowType is eventually resolved as a call to Object.GetType, since all classes are ultimately derived from the Object class.
MyBasecannot be used to callPrivateclass members.MyBasecannot be used to call base class members marked asMustOverride.
Programming Tips and Gotchas
MyBaseis commonly used to call back into the overridden member from the member that overrides it in the derived class.The
MyBasekeyword can be used to call the constructor of the base class to instantiate a member of that class, as in:MyBase.New(...)
VB.NET/VB 6 Differences
The MyBase keyword is new to VB.NET.