Saturday, October 07, 2006

The constructor method of VB.NET

A constructor is a method that runs when a new instance of the class is created.
In Visual Basic, the constructor method is always named Sub New:


Class Person
Private CreateTime As Date
Sub New()
' Display a diagnostic message.
Console.WriteLine("A new instance of Person is being created.")
' Remember when this instance was created.
CreateTime = Now
' Perform other initialization chores.

End Sub
End Class