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.
精彩评论