首页 > 解决方案 > 在 Visual BASIC .net 中声明变量是否会影响效率?

问题描述

在这个 vb.net 函数的代码片段中,在 A 点或 B 点声明变量更有效吗?

我意识到这可以在不声明 x 和 y 的情况下进行编程:返回 x + GetY() + GetZ(),但这不是我正在寻找的答案。

Private Function Sum(ByVal x As Integer)

    Dim y As Integer      ' A) declare variables here?
    Dim z As Integer

    If x <> 0 Then

      'Dim y As Integer   'B) or declare variables here?
      'Dim z As Integer

       y = GetY()
       z = GetZ()

       Return x + y + z

     Else Return x

     End If

End Function

标签: vb.net

解决方案


推荐阅读