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