开发者

Constructors calling other constructors in vb.net a la c#

In c# you can have

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

    publi开发者_如何学JAVAc Foo(string name, int bar) : this(name)
    {
        //do something
    }
}

Is there a VB.Net equivalent?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜