-
Inheritance Question
When I'm inheriting a class, how do I inherit the base classes New() method as well? Example:
Code:
Public Class CList
Inherits ArrayList
End Class
When I create a new instance of an ArrayList, I get the option to add the capacity to the array list as so..
Code:
Dim al As New ArrayList(10)
But when I create an instance of my class that inherits the arraylist, I don't get the option to intialize the capacity
Code:
Dim cl As New CList(???)
I figured it would automatically inherit the New() method , Is there a keyword to use the base class initialization code when initializing a child class?
-
Re: Inheritance Question
Hi
You always to add the constructors
Code:
public sub new ()
end sub
public sug new(byval size as integer)
end sub
And if your class uses unmanaged resourses its a good idea to implement the IDisposable interface.
Regards
Jorge
-
Re: Inheritance Question
Sorry but constructors are not inheritable.
You can do Asgorath suggestions and to take it a step further you can call the base class's constructor to do the work.
Code:
Public Sub New(ByVal size As Integer)
MyBase.New(size)
End Sub