开发者

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

开发者 https://www.devze.com 2022-12-09 12:01 出处:网络
In c# you can have public class Foo { public Foo(string name) { //do something } publi开发者_如何学JAVAc Foo(string name, int bar) : this(name)

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

精彩评论

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