tags:

views:

140

answers:

1

In c# you can have

public class Foo
{
    public Foo(string name)
    {
        //do something
    }

    public Foo(string name, int bar) : this(name)
    {
        //do something
    }
}

Is there a VB.Net equivalent?

+3  A: 

It looks similar to Java in this respect:

Public Class Foo
    Public Sub New(name As String)
        ' Do something '
    End Sub

    Public Sub New(name As String, bar As Integer)
        Me.New(name)
        ' Do something '
    End Sub
End Class

Note that you have to use MyBase.New(...) in case you want to call a constructor of a base class. See also VB.NET OOP Part2 – Understanding Constructors.

Joey
Thanks. I thought it might be something like that but I was putting Me(name) rather than Me.New
Antony Koch