0
根據調試器,我有一個名爲myCancelled
的類型爲Newtonsoft.Json.Linq.Jtoken的變量,其值爲Nothing。我也將它鑄造成Object,所有這些情況都失敗了。我的問題很簡單:如何檢查它是Nothing/Null/False/Empty?檢查Newtonsoft.Json.Linq.JToken是不是Nothing
這是我試過的。這些條件都不計算爲真:
If myCancelled Is Nothing Then
'Doesn't come here
End If
If myCancelled = DBNull.Value.ToString Then
'Doesn't come here
End If
If myCancelled = "null" Then
'Doesn't come here
End If
If IsDBNull(myCancelled) Then
'Doesn't come here
End If
If myCancelled Is DBNull.Value Then
'Doesn't come here
End If
If String.IsNullOrEmpty(myCancelled) = True Then
'Doesn't come here
End If
If myCancelled.ToString = "Nothing" Then
'Runtime error
End If
If myCancelled = DBNull.Value Then
'Runtime error
End If
If IsNothing(myCancelled) Then
'Doesn't come here
End If
我是新來VB.net所以任何指針讚賞。
編輯
這一個工作,但它通過時(myCancelled有其價值,條件是真實的)讓誤報
If Not myCancelled Then
' It comes here
End If
任何想法爲什麼「Y」是正確的相等檢查什麼時候沒有什麼是實際值? – ErikBrandsma
也許Equals()方法以我想要的方式處理Nothings。事後看來,這可能是一個更好的解決方案:https://stackoverflow.com/questions/378225/how-to-check-for-null-value-in-vb-net – chakeda