Friday, February 18, 2011

VB Constructor - Calling base constructor on overloaded new methods

You can have multiple ways to create a class, passing various parameters when you create a 'new' instance of the object. In the class constructor, you use the
Me.New() to call the base constructor, or any of the constructor signatures

public class MyClass
dim var as string
dim i as integer
dim sConnString as string

public sub New()
var = "Init"
end sub

public sub New(vInt as integer)
Me.New() ' calls base constructor
i=vInt
end sub

public sub New(vInt as integer, vConnectionString as string)
Me.New(vInt)
sConnString=vConnectionString)

end sub

No comments:

Post a Comment