Public Class clsTest
Public Sub New()
Console.WriteLine("inside default constructor")
End Sub
Public Sub clsTest(ByVal s As String)
Console.WriteLine(s)
End Sub
Public Sub clsTest(ByVal s As String, ByVal t As String)
Console.WriteLine(s & " " & t)
End Sub
End Class
-----------------------------------------------------
Private Sub btnTest_Click(...) Handles btnClsTest.Click
Dim testCls As New clsTest
testCls.clsTest("test")
testCls.clsTest("test1", "test2")
testCls = Nothing
End Sub
-------------------------------------------------------
I observed here that I cannot overload the default constructor in VB.Net
which always gets called on invocation of Class clsTest -- Dim testCls As New
clsTest. I am thinking like this:
Dim a As New clsTest
Dim b As New clsTest("test")
Dim c As New clsTest("test1", "test2")
Question: is/are
Public Sub clsTest(ByVal s As String)
....
Public Sub clsTest(ByVal s As String, ByVal t As String)
....
constructor(s) or just overloaded methods in class clsTest? I am thinking
that if you define a method in a class with the same name as the class - this
constitutes a constructor. Could someone set me straight how to overload a
constructor in VB.Net so I can do
Dim a As New clsTest
Dim b As New clsTest("test")
Dim c As New clsTest("test1", "test2")
Thanks,
Rich