我曾经这样写:
Private Sub Example()
Static CachedPeople As List(Of MyApp.Person)
If CachedPeople Is Nothing Then
CachedPeople = New List(Of MyApp.Person)
End If
...rest of code...
End Sub
但后来想知道我是否可以将其减少为:
Private Sub Example()
Static CachedPeople As New List(Of MyApp.Person)
...rest of code...
End Sub
问题是,“New”位是否只在函数第一次执行时执行一次,但在下一次调用时,它已经存在。
干杯,罗布。