在性能至關重要的應用程序中,是否會有任何明顯的優勢情景1(完全獨立的構造函數)與情景2(鏈調用構造函數)?調用其他構造函數的構造函數:任何性能問題?
方案1
Class TwoInts
Private a, b As Integer
Public Sub New(ByVal a As Integer, ByVal b As Integer)
Me.a = a
Me.b = b
End Sub
Public Sub New(ByVal a As Integer)
Me.a = a
Me.b = 0
End Sub
Public Sub New()
Me.a = 0
Me.b = 0
End Sub
End Class
方案2
Class TwoInts
Private a, b As Integer
Public Sub New(ByVal a As Integer, ByVal b As Integer)
Me.a = a
Me.b = b
End Sub
Public Sub New(ByVal a As Integer)
Me.New(a, 0)
End Sub
Public Sub New()
Me.New(0)
End Sub
End Class