.net - 构造函数调用其他构造函数: any performance issues?

标签 .net performance constructor method-chaining

在性能至关重要的应用程序中,场景 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

最佳答案

不,不会有明显的差异。

您可以运行自己的基准测试并找出答案。

关于.net - 构造函数调用其他构造函数: any performance issues?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5915678/

相关文章:

javascript - 如何以编程方式获取网页中图像的渲染尺寸?

performance - Apache 在 Tomcat 之前安装,有什么好处?

php - 在什么情况下我们应该将类构造函数设为私有(private)

c# - 我可以将 Activator.CreateInstance 与接口(interface)一起使用吗?

c# - 如何从字符串中删除无关紧要的零?

sql-server - 在 SqlServer 2008 上仅具有聚集索引的表或没有任何索引的表的更好的插入性能?

sql - Oracle 11g docker SELECT 非常慢

c++ - C++中有便利构造函数吗?

c# - MVVMCross 将值传递给具有 2 个构造函数的 ViewModel

.net - SAP 是否有标准方法将其数据库连接到外部各方?网络服务?