在 C# 中你可以拥有
public class Foo
{
public Foo(string name)
{
//do something
}
public Foo(string name, int bar) : this(name)
{
//do something
}
}
是否有 VB.Net 等效项?
最佳答案
在这方面它看起来与 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 .
关于vb.net - vb.net 中的构造函数调用 c# 中的其他构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1612371/