Constructor within a constructor

Posted by Chiramisu on Stack Overflow See other posts from Stack Overflow or by Chiramisu
Published on 2012-06-28T21:11:42Z Indexed on 2012/06/28 21:15 UTC
Read the original article Hit count: 259

Is this a bad idea? Does calling a generic private constructor within a public constructor create multiple instances, or is this a valid way of initializing class variables?

Private Class MyClass
    Dim _msg As String

    Sub New(ByVal name As String)
        Me.New()
        'Do stuff
    End Sub

    Sub New(ByVal name As String, ByVal age As Integer)
        Me.New()
        'Do stuff
    End Sub

    Private Sub New() 'Initializer constructor
        Me._msg = "Hello StackOverflow"
        'Initialize other variables
    End Sub
End Class

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about oop