为了说明的目的,我编了两个函数。你能建议我哪一个更好的练习吗?
Test2 是否对性能更好,因为它需要声明更少的变量,因此可以在系统上使用更少的内存?
Function Test1()
Dim PerformMethod_A As Boolean = True
Dim a = 1
Dim b = 2
Dim c = 3
Dim d = 4
Dim e = 5
Dim result
If PerformMethod_A Then
result = a + b
Else
result = c + d + e
End If
Return result
End Function
Function Test2()
Dim PerformMethod_A As Boolean = True
Dim result
If PerformMethod_A Then
Dim a = 1
Dim b = 2
result = a + b
Else
Dim c = 3
Dim d = 4
Dim e = 5
result = c + d + e
End If
Return result
End Function