Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MyBase.New Query

Status
Not open for further replies.

Skittle

ISP
Sep 10, 2002
1,528
US

I am working through a VB.Net book ( as you do ) and I have come across a bit of code that seems a bit redundant to me.
the book gives no explanation why it is there.

A child class inherits a parent class and in the child class with the following code:-

Code:
Public Class LineItemList
   Inherits list(Of lineItem)

   Public Sub New()
        MyBase.New
   End Sub

   Default Public Overloads readOnly Property item(ByVal I As Integer) As Line Item
    . . .
    . . .
   End Propery

   etc.

The New constructor is defined here to be exactly the same as the parent constructor
but if they are the same, why is there a need to code it at all in the child class?
The Public Sub New() definition in this class seems unnecessary to me.
Am I missing something?


Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
it is not necessary, it will be called automatically
If the base class has a constructor with no parameters that is accessible to derived classes, MyBase.New can be called automatically. If not, a base class constructor must be called with parameters, and this cannot be done automatically. In this case, the first statement of every derived class constructor must call a parameterized constructor on the base class, or call another constructor in the derived class that makes a base class constructor call
 
Thought so. Thanks.


Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top