是否有从POV性能差/的MemoryUsage之前初始化一个对象,或返回状态之后,如“样品”在:对象初始化
Function Foo() as ComplexObject
' is there a difference ??? '
' A '
' Dim obj as New ComplexObject() '
If condition Then Return Nothing
' is there a difference ??? '
' B '
Dim obj as New ComplexObject()
...
Return obj
End Function
我担心编译器会创建(并初始化)所有声明的对象(在内部循环之外)。 – serhio 2010-07-17 22:33:57
关于VB.NET中C#或IIF运算符的'?'不能用于我的情况,因为或者我返回一个Nothing(null)或者我需要用新的ComplexObject做一些事情,而不是直接返回它。 – serhio 2010-07-17 22:44:55
@serhio - *声明*发生在IL的开始处;然而,创建**必须在您的代码所说的逻辑点上发生。 – 2010-07-17 22:46:31