构造函数在vb.net中调用其他构造函数#c#

时间:2009-10-23 09:38:20

标签: vb.net

在c#中你可以拥有

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

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

是否有VB.Net等价物?

1 个答案:

答案 0 :(得分:71)

在这方面看起来与Java类似:

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

请注意,如果要调用基类的构造函数,则必须使用MyBase.New(...)。另请参阅VB.NET OOP Part2 – Understanding Constructors