我有以下代码:
Public Class TestClass
Public Sub Main()
If theGlobal IsNot Nothing Then Throw New Exception("What gives!")
End Sub
Private Shared theGlobal As Object = Nothing
Private Shared ReadOnly Property Global
Get
If theGlobal Is Nothing Then
theGlobal = New Object()
End If
Return theGlobal
End Get
End Property
End Class
Run Code Online (Sandbox Code Playgroud)
难倒......为什么全球对象不是什么?
假设这确实是你的代码,我的猜测是你在调试器中使用断点运行它,并且监视窗口正在评估正在初始化的属性theGlobal.
只是一个猜测,基于我以前在类似情况下看到的情况.
如果这没有帮助,请尝试编写一个简短但完整的控制台应用程序,它可以重现问题,并且我们都可以运行.
| 归档时间: |
|
| 查看次数: |
143 次 |
| 最近记录: |